Skip to content

Bat script to check for subnet and launch website

Featured Replies

I'm trying to write a simple script that would first check at logon if a user is on our domain and if so, launch a website.

This is so that they don't get "Page cannot be displayed" if they are not connected.

 

So far I'm playing with:

 

ipconfig > c:\IP.txt

FINDSTR "10.5" c:\IP.txt > C:\Subnet.txt

 

Now how would I use the IF command to check if 10.5 is present in the "Subnet.txt" and if so, launch the site?

 

This is probably very simple but my knowledge of scripts is limited to Google.

 

Thanks!

  • 3 weeks later...
  • Author

Anybody?

How would you go about checking an IP address and then launch a website?

  • 2 weeks later...

My batch file scripting is too rusty, so if you're not stuck on that, here's some quick VBScript code to do what you're looking for:

 

Option Explicit
Dim objWshShell, RegExp, objWMIService, colNetAdapters, objItem, strSubnetCheck
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set RegExp = new RegExp
RegExp.IgnoreCase = true
strSubnetCheck = "unknown"
Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=True")
For Each objItem In colNetAdapters
RegExp.pattern = "10.5"
If (RegExp.test (objItem.IPSubnet(0)) = TRUE) Then
 strSubnetCheck = "OnSubnet"
End If
Next
If UCase(strSubnetCheck) = UCase("OnSubnet") Then
objWshShell.Run("http://www.windows-noob.com")
End If
Wscript.Quit

  • Author

Lucid / I-MANjuel,

 

Thanks so much for your answers. This was very helpful.

As I suspected, the BATCH script was very simple and does the job perfectly!

Thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.