Author Topic: ULX GeoIP -- Look up geographical information on a user based on their IP  (Read 24414 times)

0 Members and 1 Guest are viewing this topic.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Hello, everyone!

I'd recently made a geo-IP location tool for ULX, and thought I'd release it for public use.

So, without further adieu, I present ULX GeoIP.

This tool allows you to query a GeoIP database (the script uses this one) to get semi-detailed geographical location on a user.

The applications? Lag testing, debugging, et cetera.

BIG SCARY NOTE: Please provide some kind of easily visible disclaimer to your server's MOTD or similar to prevent potential legal issues. I take no responsibility for misuse of this addon.

This script is provided free of charge, under the note that- if used maliciously, it could result in legal action against you. Again, I take no responsibility for the misuse of this script.

Some information this script provides (results may vary depending on ISP and country, also not 100% accurate):
  • Country
  • State/Region
  • City
  • Postal code
  • Latitude
  • Longitude
  • Area code

Commands:
ulx geoip <player>/!geoip <player> - Print the GeoIP data of a user to your console.

This script works for both client and server. Default access is for superadmins only.

Links:

I will reiterate once more: I do not take any responsibility whatsoever for the misuse of this addon. Any and all misuse is the fault of the end-user.
« Last Edit: July 13, 2016, 10:08:13 AM by Bytewave »
bw81@ulysses-forums ~ % whoami
Homepage

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
This is pretty sweet!
Experiencing God's grace one day at a time.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
This is pretty sweet!
Happy to hear that!
I'd used FreeGeoIP for quite a while, and- because they have a REST API- thought "Hey, why not build a Lua script so I don't have to tab out every time I want to get someone's location (for lag purposes)?"
So I did, and here we are.
bw81@ulysses-forums ~ % whoami
Homepage

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Without me going and looking, do they have a limited TOS?
Meaning, only so many look ups per day/timeframe?
I've seen server IPs banned from some tools like this due to TOS abuse.

Either way, nice idea.
If there is a TOS limit, perhaps add the limit to the script.
Would hate to hit it, but, at least it would tell us instead of an odd error/complaint here asking 'it breaks randomly'

EDIT - WOW.
1) It doesn't just list the lat/long of where my ISP is located, but, it lists the actual location of where the cable plant office/ splits for of my IP (I've rarely seen this accuracy in geo services)
2) Quote from the site "Limits - API usage is limited to 10,000 queries per hour."

Though it might be good to include that in the script anyway, 10000 is likely never to be hit, even if one were to set up the command for all player joins.
« Last Edit: October 25, 2014, 07:25:53 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Without me going and looking, do they have a limited TOS?
Meaning, only so many look ups per day/timeframe?
I've seen server IPs banned from some tools like this due to TOS abuse.

Either way, nice idea.
If there is a TOS limit, perhaps add the limit to the script.
Would hate to hit it, but, at least it would tell us instead of an odd error/complaint here asking 'it breaks randomly'
Their website says it's 10,000 queries per hour, so it's highly unlikely anyone is going to hit that.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Sadly, it doesn't seem to support IPv6 (not that many sites do)
It's my understanding that one of the first 4 :blah: subsets in a ipv6 address actually tells some type of location information.
2601:e:c580:cb2:d94b:xxxx:yyyy:zzzz (part of my current v6 ip)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Sadly, it doesn't seem to support IPv6 (not that many sites do)
It's my understanding that one of the first 4 :blah: subsets in a ipv6 address actually tells some type of location information.
2601:e:c580:cb2:d94b:xxxx:yyyy:zzzz (part of my current v6 ip)

Possibly.
I might try and find a GeoIP database for IPv6 and implement it, based on if a : is detected. I'll look into that.
Without me going and looking, do they have a limited TOS?
Meaning, only so many look ups per day/timeframe?
I've seen server IPs banned from some tools like this due to TOS abuse.

Either way, nice idea.
If there is a TOS limit, perhaps add the limit to the script.
Would hate to hit it, but, at least it would tell us instead of an odd error/complaint here asking 'it breaks randomly'

EDIT - WOW.
1) It doesn't just list the lat/long of where my ISP is located, but, it lists the actual location of where the cable plant office/ splits for of my IP (I've rarely seen this accuracy in geo services)
2) Quote from the site "Limits - API usage is limited to 10,000 queries per hour."

Though it might be good to include that in the script anyway, 10000 is likely never to be hit, even if one were to set up the command for all player joins.
That's why I never included it- 10,000 shouldn't ever be hit in an hour, even by large servers. I'll add that limit, I guess, if the issue arises.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Looks like I may have found an IPv6 GeoIP database with a Rest API. Gonna implement this into the script here shortly.

EDIT: Though it might take a few tries to get right... problem I currently face is trying to discern whether an IP is IPv6 or IPv4. Was going to see if a ":" existed in the IP, but then I realized LocalPlayer():IPAddress() returns IP + port... making the returned string "127.0.0.1:27005". :/
« Last Edit: October 25, 2014, 09:34:27 PM by Princess Twilight Sparkle »
bw81@ulysses-forums ~ % whoami
Homepage

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Does Gmod/Source server even allow for IPv6?
Though adding it would be a nice future proof...I think my statement was more a note than a 'it should be included'.

As for testing for it, check the IP for more than one colon and or no periods. Periods, to my knowledge, aren't in ipv6.
Presume end colon would be the port # after.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Does Gmod/Source server even allow for IPv6?
Though adding it would be a nice future proof...I think my statement was more a note than a 'it should be included'.

As for testing for it, check the IP for more than one colon and or no periods. Periods, to my knowledge, aren't in ipv6.
Presume end colon would be the port # after.
Yeah... see this is why I shouldn't respond to a post at 10:34 PM CT. Obvious answer is obvious. :/
I'll check and see-- mostly by trail and error, because nothing is well-documented in the world of the Garry's Mod Wiki.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: ULX GeoIP -- Look up geographical information on a user based on their IP
« Reply #10 on: October 26, 2014, 01:01:23 PM »
Based on some quick Googling, it doesn't look like Valve has enabled support for IPv6 yet.
Experiencing God's grace one day at a time.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: ULX GeoIP -- Look up geographical information on a user based on their IP
« Reply #11 on: October 26, 2014, 03:43:41 PM »
Based on some quick Googling, it doesn't look like Valve has enabled support for IPv6 yet.
Well then, looks like I won't need to add support for it yet. :P
bw81@ulysses-forums ~ % whoami
Homepage

Offline Chironex

  • Full Member
  • ***
  • Posts: 197
  • Karma: 11
  • Formerly known as Kyzer
Re: ULX GeoIP -- Look up geographical information on a user based on their IP
« Reply #12 on: October 29, 2014, 06:18:47 PM »
Personally I do it like this:

Code: [Select]
http.Fetch(
    "http://www.telize.com/geoip/" .. ( ply:IPAddress():match("%d+%.%d+%.%d+%.%d+") or "" ),
    function( data )
        ply.GeoIpData = util.JSONToTable( data )
        ...

I find Telize superior to any other free geoip tools (because I think I tried them all) ;)

Karma++ for a good try ;)

Edit: also avoid the use of SendLua, use net messages instead.
« Last Edit: October 29, 2014, 06:33:07 PM by Chironex »

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: ULX GeoIP -- Look up geographical information on a user based on their IP
« Reply #13 on: October 31, 2014, 04:07:49 PM »
Personally I do it like this:

Code: [Select]
http.Fetch(
    "http://www.telize.com/geoip/" .. ( ply:IPAddress():match("%d+%.%d+%.%d+%.%d+") or "" ),
    function( data )
        ply.GeoIpData = util.JSONToTable( data )
        ...

I find Telize superior to any other free geoip tools (because I think I tried them all) ;)

Karma++ for a good try ;)

Edit: also avoid the use of SendLua, use net messages instead.

The code was more or less hastily scrapped together at midnight, and works now. Will refactor and add net messages in next update.
bw81@ulysses-forums ~ % whoami
Homepage

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: ULX GeoIP -- Look up geographical information on a user based on their IP
« Reply #14 on: November 08, 2014, 10:09:42 AM »
After a bit of fiddling I think I've set up a system for net messages. Haven't tested it yet, still doing code work for my server.

Anyone willing to do a beta for me?
bw81@ulysses-forums ~ % whoami
Homepage