Solved

Script to determine ip address and launch a web page based on first 3 octets

Posted on 2011-02-21
5
482 Views
Last Modified: 2012-05-11
I need a script in python, or vb script which, when run on a machine, will determine the machine's IP address and then open a web browser. What I'm trying to do is check a remote LAN's IP address range to see if it's the same as my own LAN. If it is, one URL is launched. If not, another URL is launched.
Python, or vb script would be preferred.
0
Comment
Question by:lessthan2
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:Psy053
Comment Utility
Try this:
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAdapter = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=True")

For Each objItem in colAdapter
	For Each strAddress in objItem.IPAddress
		If InStr(strAddress, "192.168.1.") Then
			Results=True
		End If
	Next
Next 

If Results=True Then
	WScript.Echo "Address is within the 192.168.1.* range"
Else
	WScript.Echo "Address is not within the 192.168.1.* range"
End If

Open in new window

0
 
LVL 14

Accepted Solution

by:
Psy053 earned 500 total points
Comment Utility
Sorry, just to make it a little more complete, the script has been modified to now open IE to a particular page based on whether or not it is in the specified range:



strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAdapter = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=True")
Set objIE = CreateObject("InternetExplorer.Application") 

For Each objItem in colAdapter
	For Each strAddress in objItem.IPAddress
		If InStr(strAddress, "192.168.1.") Then
			Results=True
		End If
	Next
Next 

If Results=True Then
	objIE.Navigate "http://www.example.com/TRUE"
	objIE.Visible = True
Else
	objIE.Navigate "http://www.example.com/FALSE"
	objIE.Visible = True
End If

Open in new window

0
 
LVL 9

Expert Comment

by:Scottyworld
Comment Utility
in order to get it to open a web page you would need to add the following to Psy053's script above

2: Set Sh = WScript.CreateObject("WScript.Shell")

15: Sh.Run "http://www.google.com", 3

17: Sh.Run "http://www.experts-exchange.com/", 3
0
 
LVL 9

Expert Comment

by:Scottyworld
Comment Utility
Lol - beaten to it!
0
 

Author Closing Comment

by:lessthan2
Comment Utility
Excellent! Works perfect - Thank you.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now