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

How to get the IP addr of local computer in VBS

327 views
Skip to first unread message

JP

unread,
Apr 18, 2001, 11:18:43 PM4/18/01
to
I am writing a simple script to be distributed in email for copying a file
and making some configuration changes.

As this is not a log-on script, I have to find out the locale of the user so
as to determine from which server the file should be copied. Copying a 2MB
file across the WAN site will stall the network.

We have clients running Windows 95, therefore, envir variables won't work.
One way to identify the site of the user iss by looking at their IP address.
Since each site has its own IP segment, I can then determine the source
location.

Can anyone show me how I can get the IP address on both 95 and NT using VBS?
Or any alternatives to my problem? I realized that W2K stores the IP in the
registry, which I can use a RegRead statement to get. However, Win9x and NT
do not work the same way.

Any help will be much appreciated.

Joe


Michael Harris

unread,
Apr 19, 2001, 1:04:49 AM4/19/01
to
arAddresses = GetIPAddresses()

msgbox ubound(arAddresses)+1 & " IP Address(es) found"
for each ip in arAddresses
msgbox ip
next

msgbox GetIPAddresses()(0)


Function GetIPAddresses()
'=====
' Returns array of IP Addresses as output
' by ipconfig or winipcfg...
'
' Win98/WinNT have ipconfig (Win95 doesn't)
' Win98/Win95 have winipcfg (WinNt doesn't)
'
' Note: The PPP Adapter (Dial Up Adapter) is
' excluded if not connected (IP address will be 0.0.0.0)
' and included if it is connected.
'=====
set sh = createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")

Set Env = sh.Environment("PROCESS")
if Env("OS") = "Windows_NT" then
workfile = fso.gettempname
sh.run "%comspec% /c ipconfig > " & workfile,0,true
else
'winipcfg in batch mode sends output to
'filename winipcfg.out
workfile = "winipcfg.out"
sh.run "winipcfg /batch" ,0,true
end if
set sh = nothing
set ts = fso.opentextfile(workfile)
data = split(ts.readall,vbcrlf)
ts.close
set ts = nothing
fso.deletefile workfile
set fso = nothing
arIPAddress = array()
index = -1
for n = 0 to ubound(data)
if instr(data(n),"IP Address") then
parts = split(data(n),":")
if trim(parts(1)) <> "0.0.0.0" then
index = index + 1
ReDim Preserve arIPAddress(index)
arIPAddress(index)= trim(cstr(parts(1)))
end if
end if
next
GetIPAddresses = arIPAddress
End Function

--
Michael Harris
Microsoft.MVP.Scripting
--
mik...@mvps.org
Please do not email questions - post them to the newsgroup instead.
--

"JP" <pan...@hotmail.com> wrote in message news:ewHiH6HyAHA.2044@tkmsftngp03...

JP

unread,
Apr 19, 2001, 10:18:26 AM4/19/01
to
Work like a chime. Thank you very much.

Joe


"Michael Harris" <mik...@mvps.org> wrote in message
news:#co#D5IyAHA.1560@tkmsftngp03...

0 new messages