A little script to get country code of IP and then you can do what you like with it.
Been playing and whilst this isn't the prefered (local database) method, some may find it useful.
Main benefit is that it doesn't require you to maintain a local DB of IP numbers. It uses the Maxmind GeoLite DB and presumably they look after the updates and will deal with Maxmind changing to GeoIP2.
Obviously depends on http://freegeoip.net being up and running and the speed of response but it seems quick to me.
Works for me but you may need to play with with permissions/firewall settings if you have problems with it going external for the lookup.
Where you call it from depends what you are going to do with the code.
If you are going to reject the connection then call it from OnClientConnect otherwise you can call if from OnAcceptMessage if you are going to use the Country code for other things.
If for some reason your version of Windows doesn't have MSXML2.XMLHTTP then you should have an equivalent, I think, and you'll have to research what it is.
the call to function is:
then IPCountry will contain the country of the given IP number if its found.
If the lookup fails the IPCountry will be boolean False.
Code: Select all
Sub GetGeoIP(IP) Dim IPCountry, GeoArray Dim o Set o = CreateObject("MSXML2.XMLHTTP") o.open "GET", "http://freegeoip.net/csv/"+IP, False o.timeout = 5000000 o.send If (o.status = 200 ) Then GeoArray = Split(o.responseText, ",", -1, 1) IPCountry = GeoArray(1) IPCountry = Replace (IPCountry, """", "") Else IPCountry = Null End If End Sub