Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get IP-address

55 views
Skip to first unread message

Daedalus

unread,
Oct 30, 2003, 4:48:53 AM10/30/03
to
Hi
In order to distribute data to client-pc's only known by hostname, I'd like
to determine their actual IP-address (we use DHCP). Since laptops are
roaming, I'm looking for a vbscript-equivalent of the ping-command.
Is there any hope 4 me ?
Tanx in advance !
D


Torgeir Bakken (MVP)

unread,
Oct 30, 2003, 5:13:12 AM10/30/03
to
Daedalus wrote:

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.


' some examples
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


0 new messages