![]() GetHostNameIP = GetHostNameIP & Trim(Replace(Replace(Replace(aResult(i), "Address:", ""), "Addresses:", ""), vbTab, "")) & "," If Len(Trim(sHostName)) = 0 Then GoTo Error_Handler_Exit sResult = CreateObject("Wscript.Shell").Exec("nslookup " & sHostName).StdOut.ReadAll ' 2 Update to handle the case of multiple addressesįunction GetHostNameIP(ByVal sHostName As String) As String ' sHostName : Host name to lookup the IP address of ' Req'd Refs: Late Binding -> none required ' Copyright : The following is release as Attribution-ShareAlike 4.0 International ' Purpose : Retrieve the IP Address of a given host name ' Author : Daniel Pineault, CARDA Consultants Inc. , vbOKOnly + vbCritical, "An Error has Occurred!" Resume Error_Handler_Exit Switch(Erl = 0, "", Erl 0, vbCrLf & "Line No: " & Erl) _ "Error Description: " & Err.Description & _ "Error Source: GetHostNameIP" & vbCrLf & _ "Error Number: " & Err.Number & vbCrLf & _ ![]() ![]() MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _ If Right(GetHostNameIP, 1) = "," Then GetHostNameIP = Left(GetHostNameIP, Len(GetHostNameIP) - 1) ![]() GetHostNameIP = GetHostNameIP & Trim(Replace(Replace(Replace(aResult(i), "Address:", ""), "Addresses:", ""), vbTab, "")) & "," End If Next i If Len(Trim(aResult(i) & vbNullString)) > 0 Then If UBound(aResult) > 2 Then For i = 4 To UBound(aResult) SResult = CreateObject( "Wscript.Shell").Exec( "nslookup " & sHostName).StdOut.ReadAll If Len(Trim(sHostName)) = 0 Then GoTo Error_Handler_Exit ' Website : ' Purpose : Retrieve the IP Address of a given host name ' Copyright : The following is release as Attribution-ShareAlike 4.0 International ' (CC BY-SA 4.0) - ' Req'd Refs: Late Binding -> none required ' ' Input Variables: ' ~~~~~~~~~~~~~~~~ ' sHostName : Host name to lookup the IP address of ' ' Usage: ' ~~~~~~ ' GetHostNameIP("") ' Returns -> 52.40.49.196 ' GetHostNameIP("") ' Returns -> 2607:f8b0:4006:813::200e,172.217.10.238 ' ' Revision History: ' Rev Date(yyyy-mm-dd) Description ' ************************************************************************************** ' 1 Initial Release, Forum Help ' 2 Update to handle the case of multiple addresses ' 3 Handle blank/empty sHostName calls '- Function GetHostNameIP( ByVal sHostName As String) As String Dim sResult As String Dim aResult As Variant Dim i As Long On Error GoTo Error_Handler '- ' Procedure : GetHostNameIP ' Author : Daniel Pineault, CARDA Consultants Inc. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |