JoelCant
(Fresh Scripter)
2006-11-21 09:52 AM
Kix for detecting user location

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


LonkeroAdministrator
(KiX Master Guru)
2006-11-21 10:07 AM
Re: Kix for detecting user location

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


JoelCant
(Fresh Scripter)
2006-11-28 11:23 AM
Re: Kix for detecting user location

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


NTDOCAdministrator
(KiX Master)
2006-11-28 11:28 AM
Re: Kix for detecting user location

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.


Richard H.Administrator
(KiX Supporter)
2006-11-28 12:07 PM
Re: Kix for detecting user location

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.


JoelCant
(Fresh Scripter)
2006-11-28 12:28 PM
Re: Kix for detecting user location

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


Richard H.Administrator
(KiX Supporter)
2006-11-28 01:38 PM
Re: Kix for detecting user location

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


Les
(KiX Master)
2006-11-28 03:09 PM
Re: Kix for detecting user location

;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!


JoelCant
(Fresh Scripter)
2006-11-28 05:30 PM
Re: Kix for detecting user location

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


Les
(KiX Master)
2006-11-28 06:38 PM
Re: Kix for detecting user location

I don't understand what you are after but the following is not right.
Code:
$stringPing = RUN "ping /n 4 "$sIP 


AllenAdministrator
(KiX Supporter)
2006-11-28 06:52 PM
Re: Kix for detecting user location

Do a search in the UDF Library for WSHPipe. Make sure to change the search dates to the past couple of years.

Richard H.Administrator
(KiX Supporter)
2006-11-29 09:23 AM
Re: Kix for detecting user location

You might also use the wmiPing UDF.

NTDOCAdministrator
(KiX Master)
2006-11-29 09:25 AM
Re: Kix for detecting user location

Yes, but don't forget.

Quote:
DEPENDENCIES:
; Windows XP or Server 2003
;