Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launch programs based on IP address

Status
Not open for further replies.

iandunn01

Technical User
Oct 20, 2004
6
US
I'm trying to create a script that will run a few programs if I have a certain IP address. I know some C++, and did some VB years ago, but am having trouble with this VBScript. There's a syntax error w/ the if statement, but I'm not sure what it is...


set WshShell = WScript.CreateObject("WScript.Shell")

strComputer = "dunniana-ws"
set png = WshShell.exec("ping -n 1 " & strComputer)
do until png.status = 1 : wscript.sleep 10 : loop
strPing = png.stdout.readall

Select Case True
Case InStr(strPing, "Request timed out") > 1
strReply = "Request timed out"
strIpAddress = GetIP(strPing)
Case InStr(strPing, "could not find host") > 1
strReply = "Host not reachable"
strIpAddress = "N/A"
Case InStr(strPing, "Reply from") > 1
strReply = "Ping Succesful"
strIpAddress = GetIP(strPing)
End Select


If (strIPAddress >= "192.168.1.2" And strIPAddress <= "192.168.1.254") Or
(strIPAddress >= "140.106.244.2" And strIPAddress <= 140.106.244.254")


WScript.Sleep 5000
WshShell.Run "firefox.exe"
WScript.Sleep 6500
WshShell.Run "thunderbird.exe"
WScript.Sleep 1000
WshShell.Run "gaim.exe"

End If


Function GetIP(ByVal reply)
Dim P
P = Instr(reply,"[")
If P=0 Then Exit Function
reply = Mid(reply,P+1)
P = Instr(reply,"]")
If P=0 Then Exit Function
GetIP = Left(Reply, P-1)
End Function
 
Hello iandunn01,

Try this.
[tt]
If (strIPAddress >= "192.168.1.2" And strIPAddress <= "192.168.1.254") Or [COLOR=red yellow]_[/color]
(strIPAddress >= "140.106.244.2" And strIPAddress <= [COLOR=red yellow]"[/color]140.106.244.254") [COLOR=red yellow]Then[/color]
[/tt]
regards - tsuji
 
Anyway be aware that 192.168.1.3 is greater than 192.168.1.254

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello all,

I'd considered only syntax. Taking into account of PHV's remark, compare should be done more properly via a transformation. Such as...
[tt]
s="192.168.1.3"
a=split(s,".")
curs=""
for i=0 to ubound(a)
curs=curs & right("000" & a(i),3)
next
curs=ccur(curs) 'use curs as a base for comparison
wscript.echo curss
[/tt]
- tsuji
 
correction: typos (last line)

[tt]wscript.echo curs[/tt]

- tsuji
 
Thanks for the help guys, that fixed the error. I should have known I couldn't compare the IP addresses in that form...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top