Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-21
5
Medium Priority
?
516 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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…

670 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