Thanks.
> Hi. How can i traslate the ip adress of a computer of the network to his
> computer name?
Hi
Here is a VBScript function that uses nslookup.exe that comes with WinNT, Win2k
and WinXP.
It supports both lookup and reverse lookup, it will detect if the input
parameter is an ip address or not and act accordingly.
WScript.Echo NSlookup("www.microsoft.com")
WScript.Echo NSlookup("desktop-3.some.ert.com")
WScript.Echo NSlookup("250.124.58.9")
WScript.Echo NSlookup("127.0.0.1")
Function NSlookup(sHost)
' Both IP address and DNS name is allowed
' Function will return the opposite
Set oRE = New RegExp
oRE.Pattern = "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
bInpIP = False
If oRE.Test(sHost) Then
bInpIP = True
End If
Set oShell = CreateObject("Wscript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\" & oFS.GetTempName
'Run NSLookup via Command Prompt
'Dump results into a temp text file
oShell.Run "%ComSpec% /c nslookup.exe " & sHost _
& " >" & sTempFile, 0, True
'Open the temp Text File and Read out the Data
Set oTF = oFS.OpenTextFile(sTempFile)
'Parse the text file
Do While Not oTF.AtEndOfStream
sLine = Trim(oTF.Readline)
If LCase(Left(sLine, 5)) = "name:" Then
sData = Trim(Mid(sLine, 6))
If Not bInpIP Then
'Next line will be IP address(es)
'Line can be prefixed with "Address:" or "Addresses":
aLine = Split(oTF.Readline, ":")
sData = Trim(aLine(1))
End If
Exit Do
End If
Loop
'Close it
oTF.Close
'Delete It
oFS.DeleteFile sTempFile
If Lcase(TypeName(sData)) = LCase("Empty") Then
NSlookup = ""
Else
NSlookup = sData
End If
End Function
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter