Board index » Visual Studio » get ip adress
|
dmw47
|
|
dmw47
|
get ip adress
Visual Studio358
How can i catch the ip adress with vbscript and use it to map my network drives ? - |
| Torgeir
Registered User |
Tue Jun 15 15:03:51 CDT 2004
Re:get ip adress
Francois Deveault wrote:
QuoteHow can i catch the ip adress with vbscript and If you need to test on octet "ranges", take a look at this link: http://groups.google.com/groups?selm" rel="nofollow" target="_blank">groups.google.com/groups=3F8060D4.7C0B9190%40hydro.com Here is a simplified variant of the script in the link above: ' get IP address(es) in an array aNICstatus = GetIPAddresses ' If several IP addresses are returned, use the last one sIp = aNICstatus(UBound(aNICstatus)) WScript.Echo "IP address is: " & sIp Function GetIPAddresses() '===== ' Based on a Michael Harris script, modified be Torgeir Bakken ' ' 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 = Env("TEMP") & "\" & fso.gettempname sh.run "%comspec% /c ipconfig>" & Chr(34) & workfile & Chr(34),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) data(n) = replace(data(n),vbCr,"") if instr(data(n),"IP Address") then parts = split(data(n),":") 'if trim(parts(1)) <>"0.0.0.0" then if instr(trim(parts(1)), "0.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 -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: www.microsoft.com/technet/community/scriptcenter/default.mspx">www.microsoft.com/technet/community/scriptcenter/default.mspx - |
