IP To Country



Prints the Country, City and Region to the chat when someone joins, spawns and disconnects. They are optional and can be customised with ip_to_country_template.

List of cvars (console commands):

[li]ip_to_country_enable 1
[/li][li]ip_to_country_template_connect “{NAME} connected from {CITY}, {REGION}, {COUNTRY}”,
[/li][li]ip_to_country_template_disconnect “{NAME} disconnected from {CITY}, {REGION}, {COUNTRY}”
[/li][li]ip_to_country_template_spawn “{NAME} spawned from {CITY}, {REGION}, {COUNTRY}”
[/li][li]ip_to_country_template_name “”
[/li][li]ip_to_country_show_connect 1
[/li][li]ip_to_country_show_disconnect 1
[/li][li]ip_to_country_show_spawn 1

List of template words you can use for connect disconnect and spawn:

[li]{NAME} = Players name.
[/li][li]{STATUS} = user group such as SuperAdmin, Player and Admin. You can create friendly names for the groups in lua/autorun/iptocountry.lua at the top. Will return “(unknown status)” on connect
[/li][li]{STEAMID} Will return “(unknown steamid)” on connect

Available template words for ip_to_country_template_name:
[li]{SHORT} = short country name at the beginning of the
[/li][li]{FULL} = full country name

How to enable country tags:

ip_to_country_template_name "[{FULL}] "
ip_to_country_template_name "[{SHORT}] "

if the person was from Norway {SHORT} makes it only add NO in front of the name while {FULL} makes it add Norway in front of the name.

Notice the [ and ] plus the space. You can even use "({FULL}) " if you want which would make it say “(Norway) CapsAdmin”

If you want you can add colors to countries. The configuration is located at the top of lua/autorun/iptocountry.lua. I’ve added Norway and NO to be red as an example.

How to disable country tags

Simply set the cvar to “”

ip_to_country_template_name “”

How to use it in your own script:

To use in your own script or something use IPToCountry.QueryIP(ip, callbackfunction) (it’s shared)
IPToCountry.QueryIP(“”,function(data) PrintTable(data) end)




Thanks to Roberto Ierusalimschy for the XML parsing script.
Thanks to www.ipinfodb.com for the GeoLocation API.

I should note that it returns the ISP’s location for those who don’t know.

Looks nice! If I joined from Iowa, US, what would it say for the region?

I don’t know, aren’t you supposed to know what region you’re in? (if that’s where you’re from)

I think that would be where the gateway is. They can’t pinpoint your home.



Well sometimes they can.

I got my friend’s address through a whois, as for whatever reason that’s how his network did it.

He was pissed at me :l.

i fucking love you caps

So, Norway? I believe if I connected, it would say Hirtshals, Jutland, Denmark, then?

Anyway, looks nice.

If that’s what http://www.ip2location.com/ib2/ says, then yes.
This is a very useful script that i might be able to use for several things! Thanks!

Nice script, I’ve seen it on your server.

I think it should only list the country since the province/state and city are usually wrong.

You can always change the template convar.

I’m sure people will make a script that let certain countries to come or not on their server… :frowning:

Oh noes, the first thing that come to my mind are these fucking french only servers.
Who cares for a country if the person speaks english and doesn’t act like some weirdo.

Unfortunately, or fortunately depending on who/what is trying to track my browsing and connection habits, the specific GeoIP service this is based on has had IP to location wrong for several years.
The ISP isn’t based, nor is my house, anywhere the location it states I’m at.

I’ve not attempted to correct them.

Edit - I didn’t mention, I do like the idea CapsAdmin. It is my belief that the particular dataset just isn’t correct.
Apparently there are better out there but I’ve not researched them. I just grow tired of seeing the occasional side banner add slip through my noflash and noscript plugins and say “Hi, want to meet hot chicks near <my town>? Click here!”
Somebody has it right… just not this one.

So, what happens if someone connects from or LAN?

I guess it would say UNKNOWN n/a or something like that instead of the country/city/etc.




The script should sugar-coat it and say “connecting from your own home” or something :stuck_out_tongue:

I think I’m gonna add more template words such as {STEAMID} {IP} {STATUS} (status being admin or player) and maybe colors so you can make country stand out or something.

Oh and I’ll make it so disconnect, connect and spawned has different templates.

Any ideas for template words? Maybe simple colors such as {BLUE} and so on.

It willz crash the interwebz.

Nice script. Cool addon for those who use it.