Page 1 of 1 1
Topic Options
#170555 - 2006-11-21 09:52 AM Kix for detecting user location
JoelCant Offline
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
#170556 - 2006-11-21 10:07 AM Re: Kix for detecting user location
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, do you have ip range set for vpn clients?
if you have, you can test against that ip-range with @ipAddress0, @ipAddress1, @ipAddress2 and @ipAddress3

Top
#170772 - 2006-11-28 11:23 AM Re: Kix for detecting user location [Re: Lonkero]
JoelCant Offline
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
#170773 - 2006-11-28 11:28 AM Re: Kix for detecting user location [Re: JoelCant]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Well I don't think that is a very solid method for determining connection speed.

But if you want to do it then you'd probably need to use FIND to locate the data and then put it together and perform the math on it.

A bit late for me here but if you need Silver Platter code then you'll need to ask and see if someone can help you further this morning as I'm about to get to bed now.

Top
#170774 - 2006-11-28 12:07 PM Re: Kix for detecting user location [Re: NTDOC]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
This might work for you:
Code:
$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 Offline
Fresh Scripter

Registered: 2006-11-16
Posts: 6
Code:
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 Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
How about this:
Code:
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
#170785 - 2006-11-28 03:09 PM Re: Kix for detecting user location [Re: Richard H.]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
;RUN 'c:\robocopy "c:\documents and settings\$username\My Documents" H:\$backuplocation /MIR /R:5 /W:10'
Never hard code the username in the path. Either use %userprofile% or pull it from the reg.
Don't embed vars in strings. Concatenate!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#170786 - 2006-11-28 05:30 PM Re: Kix for detecting user location [Re: Les]
JoelCant Offline
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
#170787 - 2006-11-28 06:38 PM Re: Kix for detecting user location [Re: JoelCant]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't understand what you are after but the following is not right.
Code:
$stringPing = RUN "ping /n 4 "$sIP 
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#170788 - 2006-11-28 06:52 PM Re: Kix for detecting user location [Re: JoelCant]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Do a search in the UDF Library for WSHPipe. Make sure to change the search dates to the past couple of years.
Top
#170810 - 2006-11-29 09:23 AM Re: Kix for detecting user location [Re: Allen]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You might also use the wmiPing UDF.
Top
#170811 - 2006-11-29 09:25 AM Re: Kix for detecting user location [Re: Richard H.]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Yes, but don't forget.

Quote:
DEPENDENCIES:
; Windows XP or Server 2003
;

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.057 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org