I had a requirement to find computer name from a list of IP addersses. I wrote the following vb script function for my requirement. I made it more generic function so any one can use it. Here it is.
‘Function to find Hostname from IP address. To run this function,
‘you have to be administrator to the targer computer.
‘
‘ Function Name: HostName
‘ Parameters: IP Address as a string
‘ Returns Hostname string
‘
Function HostName (IPAddress)
Dim objWMI, objItem, colItemsOn Error Resume Next
‘ Get local WMI CIMv2 object
Set objWMIService = GetObject(“winmgmts:\\” & IPAddress & “\root\cimv2”)
If Err.Number <> 0 Then
HostName = “Error”
Err.Clear
On Error Goto 0
Exit Function
End If
On Error Goto 0Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_ComputerSystem”, “WQL”, _
wbemFlagReturnImmediately + wbemFlagForwardOnly)For Each objItem In colItems
HostName = objItem.Name
NextSet colItems = Nothing
Set objWMI = Nothing
End Function
‘ – – – – End of Function – – – –
Does not run. Ends with a lot of errors.
Great script trashd by formatting! 🙂
Replac all the ‘ with ‘ and “ and ″with ” and it all works a treat. Much more satisfactory than runnign NSLookup in a shell. Thanks to poster.
Yep, I even fixed all the formatting errors due to the website. All these websites screw up the ” marks. I don’t get an error after that but I did get a big fat nothing.
and the reverse…
https://www.blogger.com/blogger.g?blogID=7228654713188232894#editor/target=post;postID=284404691534520922;onPublishedMenu=allposts;onClosedMenu=allposts;postNum=0;src=postname