Search the Community
Showing results for tags 'sre geo ip ip2location'.
-
Here are a couple of examples to find the geographical location of an IP address using various databases located around the Internet. IpToCountry.csv: #include <Array.au3> #include <Constants.au3> #cs Initial discussion: http://www.autoitscript.com/forum/topic/147550-sre-guru-challenge/ #ce Example() Func Example() Local $sIP = '74.125.224.72' ; 'Google IP' Local $sString = _IPv4ToInt($sIP) Local $sRead = FileRead(@ScriptDir & '\IpToCountry.csv') ; http://software77.net/geo-ip/ Local $hTimer = TimerInit() Local $aArray = StringRegExp($sRead, '"(' & StringLeft($sString, 2) & '\d{6,8})","(\d{8,10})","([a-z]+)","(\d{8,10})","([A-Z]{2})","([A-Z]{2,3})","([a-zA-Z ]+)"\n', 3) If @error = 0 Then Local $aReturn[7] For $i = 0 To UBound($aArray) - 1 Step 7 If $sString >= $aArray[$i] And $sString <= $aArray[$i + 1] Then $aReturn[0] = $aArray[$i] $aReturn[1] = $aArray[$i + 1] $aReturn[2] = $aArray[$i + 2] $aReturn[3] = $aArray[$i + 3] $aReturn[4] = $aArray[$i + 4] $aReturn[5] = $aArray[$i + 5] $aReturn[6] = $aArray[$i + 6] ExitLoop EndIf Next ConsoleWrite(TimerDiff($hTimer) & @CRLF) _ArrayDisplay($aReturn) Else MsgBox($MB_SYSTEMMODAL, '', 'Well an error occurred. Sorry.') EndIf EndFunc ;==>Example Func _IPv4ToInt($sString) ; By JohnOne Local $aStringSplit = StringSplit($sString, '.', 3) Local $iOct1 = Int($aStringSplit[0]) * (256 ^ 3) Local $iOct2 = Int($aStringSplit[1]) * (256 ^ 2) Local $iOct3 = Int($aStringSplit[2]) * (256) Local $iOct4 = Int($aStringSplit[3]) Return $iOct1 + $iOct2 + $iOct3 + $iOct4 EndFunc ;==>_IPv4ToInt