Solved

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

Posted on 2011-02-21
5
503 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:Psy053
ID: 34947600
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
ID: 34947620
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
ID: 34947637
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
ID: 34947640
Lol - beaten to it!
0
 

Author Closing Comment

by:lessthan2
ID: 34947685
Excellent! Works perfect - Thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
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 modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

734 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