IP Geo-Location
System Information
This attribute lists an approximate location of the machine based on it's current external IP address. This attribute applies to both Mac and Windows.
string
#!/bin/sh
myIP=`curl -L -s --max-time 10 http://checkip.dyndns.org | egrep -o -m 1 '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'`
myLocationInfo=`curl -L -s --max-time 10 http://freegeoip.appspot.com/xml/$myIP`
myCountryCode=`echo $myLocationInfo|egrep -o '<CountryCode>.*</CountryCode>'| sed -e 's/^.*<CountryCode/<CountryCode/' | cut -f2 -d'>'| cut -f1 -d'<'`
myCity=`echo $myLocationInfo|egrep -o '<City>.*</City>'| sed -e 's/^.*<City/<City/' | cut -f2 -d'>'| cut -f1 -d'<'`
myRegionName=`echo $myLocationInfo|egrep -o '<RegionName>.*</RegionName>'| sed -e 's/^.*<RegionName/<RegionName/' | cut -f2 -d'>'| cut -f1 -d'<'`
echo "<result>$myCity, $myRegionName - $myCountryCode</result>"
VBScript
On Error Resume Next
url="http://checkip.dyndns.org"
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Set xmldoc = WScript.CreateObject("msxml2.domdocument")
Call objHTTP.Open("GET", url, FALSE)
objHTTP.Send
arrIP = Split(objHTTP.responseText, "IP Address: ")
strIP = Replace(arrIP(1), "</body></html>", "")
url="http://freegeoip.appspot.com/xml/" & strIP & ""
Call objHTTP.Open("GET", url, FALSE)
objHTTP.send
xmldoc.loadXML(objHTTP.responseText)
Set objNodeList = xmlDoc.getElementsByTagName("CountryCode")
For i = 0 To (objNodeList.length - 1)
strCC = strCC & objNodeList.Item(i).text
Next
Set objNodeList = xmlDoc.getElementsByTagName("RegionName")
For i = 0 To (objNodeList.length - 1)
strR = strR & objNodeList.Item(i).text
Next
Set objNodeList = xmlDoc.getElementsByTagName("City")
For i = 0 To (objNodeList.length - 1)
strCity = strCity & objNodeList.Item(i).text
Next
WScript.Echo "<result>" & strCity & "," & strR & "," & strCC & "</result>"