Jump to content


  • 0
jpodlipny

Bat script to check for subnet and launch website

Question

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!

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

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

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.