Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get hostname from IP

Status
Not open for further replies.

pgordemer

IS-IT--Management
Dec 10, 2002
80
US
I already have a command lined script that I use to get the logged in user of a computer name that works well. But many times my network monitor programs only return the IP address of a problem user. So then I have to do a Ping -A ip.ip.ip.ip to get the hostname so I can then run my code.

Is there a easy way in VBS to convert the IP to host name so I can then pass it onto the rest of the script.

Here is what I use now for the getuser script:

Code:
On Error Resume Next


Set objArgs = WScript.Arguments
If objArgs.Count = 0 Then
	MsgBox "GETUSER.VBS" & vbCRLF & _ 
			"Gets the name of the logged in user on a computer" & vbCRLF & vbCRLF & _
			"Usage: GETUSER computer1 computer2 computer3 ..." & vbCRLF
	WScript.quit
End If

For i = 0 To objArgs.Count - 1
	strComputer = objArgs(i)
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	If err <> 0 Then
		MsgBox "Computer: " & UCase(strComputer) & " not found"
		err.clear
	Else
		Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
   	For Each objItem In colItems
			If Len(objItem.UserName) > 1  Then
				MsgBox "Computer: " & UCase(strComputer) & vbCRLF & "Logged in User: " & objItem.UserName & vbCRLF 
			Else
				MsgBox "Computer: " & UCase(strComputer) & vbCRLF & "No user logged in" & vbCRLF 
			End If
	   Next
		Set objItem = Nothing
		Set colItems = Nothing
		Set objWMIService = Nothing
	End If   
Next

So the goal is to enter GETUSER IP.IP.IP.IP and it convert the hostname and do the lookup of the logged in user.

Thanks

Phil Gordemer
ARH Associates
 
What about objItem.Caption or objItem.Name ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I think I may have answered by own question, I never tried my own script with just passing the IP address and it works. So I look like I just need to pick up the computer name if an IP address is returned from the command line.

Phil Gordemer
ARH Associates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top