I am trying to create VBScript that will detect if the computer on which it is running is running on our local network, checking its IPv4 address (assigned by DHCP) and then opening a specific URL depending on whether inside or outside our network. The script will be mainly used on laptops that will move between work (10.12.90.0/22) and the home (usually 192.168 / 23, but it could be something really). In both cases, I need to open the URL only once, because there will almost always be more than one network adapter (wired / wireless / bluetooth, etc.).
The following shows how the script works when I tested it, but I am not a programmer. I am not sure if there is a better way to do this. Ideally, I would like to avoid pinging servers due to latency.
strComputer = "." strInternal = "http://intranet/" strExternal = "http://www.mydomain.com/" Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True",,48) For Each objItem in colItems strIPAddress = objItem.IPAddress(0) arrIPAddress = Split(strIPAddress, ".") If (arrIPAddress(0) = "10") And (arrIPAddress(1) = "12") Then ipChecked = 1 Run strInternal Else If ipChecked = 1 Then WScript.Sleep(10) Else ipChecked = 1 Run strExternal End If End If Next Sub Run(ByVal sFile) Dim shell Set shell = CreateObject("WScript.Shell") shell.Run Chr(34) & sFile & Chr(34), 1, false Set shell = Nothing End Sub
source share