#170555 - 2006-11-21 09:52 AM
Kix for detecting user location
|
JoelCant
Fresh Scripter
Registered: 2006-11-16
Posts: 6
|
All,
First post so bear with me. I'm trying to use kix as a wrapper to robocopy, but I need a way to work out what connection is being utilized. We want these to run without user interaction, so need a way for kix running on the users laptop to detect weather they are on a VPN link, or the local LAN, or their T Mobile wireless card.
Any Ideas?
Joel
|
Top
|
|
|
|
#170772 - 2006-11-28 11:23 AM
Re: Kix for detecting user location
[Re: Lonkero]
|
JoelCant
Fresh Scripter
Registered: 2006-11-16
Posts: 6
|
The way I've decided to look at it, is to use a 4 packet ping to their local server. Taking the average response time and averaging it, and if its under 100ms than start the backup.
Any ideas how I'd even start doing that?
Joel
|
Top
|
|
|
|
#170774 - 2006-11-28 12:07 PM
Re: Kix for detecting user location
[Re: NTDOC]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
This might work for you:
$sServerIP="10.10.0.1"
$iMaxHops=5
$iWait=1000
If IPIsClose($sServerIP,$iMaxHops)
"Server "+$sServerIP+" is within "+$iMaxHops+" hops."+@CRLF
Else
"Server "+$sServerIP+" is down or too far away"+@CRLF
EndIf
Function IPIsClose($sIP,Optional $iHops, Optional $iWait)
If VAL($iHops)<1 $iHops=30 EndIf
If VAL($iWait)<1 $iWait=1000 EndIf
SHELL %COMSPEC%+" /C tracert -d -h "+$iHops+" -w "+$iWait+" "+$sIP+' | FIND "ms '+$sIP+'" >NUL:'
$IPIsClose=Not @ERROR
Exit @ERROR
EndFunction
Basically you use tracert to determine if the IP address is within a number of hops.
An alternative is to do a tracert, capture the output, then check the three RTTs on the last line if it matches the server IP address. Look up the PIPE udfs if you want to use this method.
|
Top
|
|
|
|
#170776 - 2006-11-28 12:28 PM
Re: Kix for detecting user location
[Re: Richard H.]
|
JoelCant
Fresh Scripter
Registered: 2006-11-16
Posts: 6
|
break ON
cls
;Home server Subnet
$baseIP = "10.203.4"
DIM $IP
$check = 0
$username = "joel.cant"
$backuplocation = "H:\"
$IP = Join(Split(@IPADDRESS0," "),'')
If Instr($IP,$baseIP)
$check = 1
else
$IP = Join(Split(@IPADDRESS1," "),'')
If Instr($IP,$baseIP)
$check = 1
else
$IP = Join(Split(@IPADDRESS2," "),'')
If Instr($IP,$baseIP)
$check = 1
else
$IP = Join(Split(@IPADDRESS3," "),'')
If Instr($IP,$baseIP)
$check = 1
else
$check = 0
endif
endif
endif
endif
if ($check = 1)
? "Run Backup"
? "Backup Will run when you strike a key" get $x
;RUN 'c:\robocopy "c:\documents and settings\$username\My Documents" H:\$backuplocation /MIR /R:5 /W:10'
exit
else
exit
endif
On better thinking I've come up with that. How do I escape the run command to allow the variables to be seen in the command line.
Thanks
Joel
|
Top
|
|
|
|
#170779 - 2006-11-28 01:38 PM
Re: Kix for detecting user location
[Re: JoelCant]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
How about this:
Break ON
CLS
;Home server Subnet
$baseIP = "10.203.4"
$backuplocation = "H:\"
$IPLIST = Join(Split("|"+@IPADDRESS0+"|"+@IPADDRESS1+"|"+@IPADDRESS2+"|"+@IPADDRESS3," "),'')
If Instr($IPLIST,"|"+$baseIP+".")
"Run Backup"+@CRLF
"Backup Will run when you strike a key"+@CRLF
Get $x
SHELL 'c:\robocopy "'+%USERPROFILE%+'" "'+$backuplocation+'" /MIR /R:5 /W:10'
EndIf
|
Top
|
|
|
|
#170786 - 2006-11-28 05:30 PM
Re: Kix for detecting user location
[Re: Les]
|
JoelCant
Fresh Scripter
Registered: 2006-11-16
Posts: 6
|
Cheers for the input guys
One last question, how do I grab executed command output and trim it down
$sIP = "10.203.1.51"
$stringPing = RUN "ping /n 4 "$sIP $splitstring = Split($stringPing,"Average = ")
I want just the number from the ms part of a ping command.
Joel
|
Top
|
|
|
|
#170810 - 2006-11-29 09:23 AM
Re: Kix for detecting user location
[Re: Allen]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You might also use the wmiPing UDF.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|