Solved

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

Posted on 2011-02-21
5
512 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

617 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