SA-MP Forums Archive
[Include] IP Lookup Script - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] IP Lookup Script (/showthread.php?tid=607276)



IP Lookup Script - Banana_Ghost - 17.05.2016

Hi,

Emmet was the original designer of the code (Original Thread: https://sampforum.blast.hk/showthread.php?tid=521843). I picked this up off the forums a while ago after I got tired of updating GeoIP databases. Unfortunately, the code I found from Emmet's post no longer worked as the search API no longer worked. So I found a new API that did work, reworked the code around to get it to work with the new API, and added support for viewing the ISP of an IP Address.

Functions:
Code:
GetPlayerCountry(playerid, country[], size = sizeof(country));
GetPlayerRegion(playerid, region[], size = sizeof(region));
GetPlayerCity(playerid, city[], size = sizeof(city));
GetPlayerISP(playerid, isp[], size = sizeof(isp));
GetPlayerTimezone(playerid, timezone[], size = sizeof(timezone));
GetPlayerZipcode(playerid, zipcode[], size = sizeof(zipcode));
Callback:
Code:
public OnLookupComplete(playerid){

    return 1;
}
Using things like this saves a lot of time by not having to ALT + Tab to ****** an IP Address to find the information.

API used is http://ip-api.com.

Note if you do over 150 queries within 1 minute, you'll get your server's IP banned for flooding.

Complete documentation for the API is here.

Link:
http://pastebin.com/h7MYhriH


Re: IP Lookup Script - JustMe.77 - 17.05.2016

Hi, I'd like to know whats the difference between this Script and Whitetigers GeoIP Plugin?


Re: IP Lookup Script - Banana_Ghost - 18.05.2016

Quote:
Originally Posted by JustMe.77
View Post
Hi, I'd like to know whats the difference between this Script and Whitetigers GeoIP Plugin?
This script pulls the information directly from the Internet using SA-MP's HTTP function.

Whitetiger's script pulls the information from SQLite databases.


Re: IP Lookup Script - Miller007 - 18.05.2016

looks nice (y)


Re: IP Lookup Script - Zorono - 18.05.2016

Good work


Re: IP Lookup Script - justice96 - 18.05.2016

Is this accurate to detect players city/country/region? seems like the API is down


Re: IP Lookup Script - Banana_Ghost - 18.05.2016

Quote:
Originally Posted by justice96
View Post
Is this accurate to detect players city/country/region? seems like the API is down
It's accuracy is approx ~50 miles most likely, not every city has IP addresses geo-located to them. As far as I've tested, the actual country and ISP is accurate.

The API is working fine, my guess to why it isn't working for you is because you're trying to use it on a SA-MP server on your actual computer. If that's the case, it isn't going to work as your IP is a local IP address.

If you want to test it, use http://ip-api.com/json/iphere


Respuesta: IP Lookup Script - dannypanda05 - 18.05.2016

I would like to see the speed of the script


Re: IP Lookup Script - HydraHumza - 18.05.2016

example script would be useful or would be good if we can directly call GetPlayerCountry and other stuff.


Re: IP Lookup Script - Private200 - 18.05.2016

It's not a hard code to use, pretty much like GetPlayerName.

pawn Code:
new pCountry[50];

GetPlayerCountry(playerid, pCountry, sizeof pCountry);
printf("The player whose ID is %d is from %s", playerid, pCountry);
It will print the player country when executed. Everything works pretty fine. As the API will search directly using your IP and not one given from SAMP, it will not work on local computer as it sends local IP. As far as the API is online and the IP sent is valid, everything will be working pretty fine. Nice work on this include, repped. Keep it up.

Edit: OnLookupComplete will not be called if IP is invalid or local.


Re: IP Lookup Script - N0FeaR - 18.05.2016

Good job keep it up!


Re: IP Lookup Script - muhsah007 - 02.06.2016

Код:
[02/06/2016 12:08:35] [join] xxxxxxx has joined the server (4:93.87.xxx.xxx)
[02/06/2016 12:08:35] [debug] Server crashed while executing GM.amx
[02/06/2016 12:08:35] [debug] AMX backtrace:
[02/06/2016 12:08:35] [debug] #0 native CallLocalFunction () from samp-server.exe
[02/06/2016 12:08:35] [debug] #1 000212b8 in public HTTP_OnLookupResponse (index=4, response=200, data[]=@007c125c "{"as":"AS8400 TELEKOM SRBIJA a.d.","city":"Belgrade","country":"Serbia","country...") at E:\Grand Theft Auto Server\pawno\include\ipl.inc:65
[02/06/2016 12:08:35] [debug] Native backtrace:
[02/06/2016 12:08:35] [debug] #0 0047467c in ?? () from samp-server.exe
[02/06/2016 12:08:35] [debug] #1 004010b6 in ?? () from samp-server.exe
[02/06/2016 12:08:35] [debug] #2 74e762ca in ?? () from plugins\crashdetect.dll
[02/06/2016 12:08:35] [debug] #3 74e78b28 in ?? () from plugins\crashdetect.dll
[02/06/2016 12:08:35] [debug] #4 74e709c7 in ?? () from plugins\crashdetect.dll
[02/06/2016 12:08:35] [debug] #5 74e7631a in ?? () from plugins\crashdetect.dll
[02/06/2016 12:08:35] [debug] #6 72c051b9 in ?? () from plugins\streamer.dll
[02/06/2016 12:08:35] [debug] #7 00480cd0 in ?? () from samp-server.exe
[02/06/2016 12:08:35] [debug] #8 004912c7 in ?? () from samp-server.exe
This include crashes my server whenever this player connects.


Re: IP Lookup Script - zSuYaNw - 02.06.2016

Goood Woork!


Re: IP Lookup Script - vannesenn - 02.06.2016

Give us code from ipl.inc from line 65


Re: IP Lookup Script - PT - 04.06.2016

I like the job you did here..

nice work


Re: IP Lookup Script - muhsah007 - 04.06.2016

Quote:
Originally Posted by vannesenn
Посмотреть сообщение
Give us code from ipl.inc from line 65
Код:
public HTTP_OnLookupResponse(index, response, data[])
{
	new pos = -1;

	if (!IsPlayerConnected(index)) return 0;
	else if (response == 200)
	{
	    if (strfind(data, "Reserved", true) != -1 || strlen(data) < 15)
		{
	        return 0;
		}
		else
		{
			new country[MAX_COUNTRY_NAME],region[MAX_COUNTRY_NAME],city[MAX_COUNTRY_NAME],isp[MAX_COUNTRY_NAME];

			if ((pos = strfind(data, "\"country\":")) != -1)
			{
			    pos = pos + 11;

				strmid(country, data, pos, strfind(data, "\"", true, pos), MAX_COUNTRY_NAME);
			}
			if ((pos = strfind(data, "\"regionName\":")) != -1)
			{
			    pos = pos + 14;

				strmid(region, data, pos, strfind(data, "\"", true, pos), MAX_COUNTRY_NAME);

			}
			if ((pos = strfind(data, "\"city\":")) != -1)
			{
			    pos = pos + 8;

				strmid(city, data, pos, strfind(data, "\"", true, pos), MAX_COUNTRY_NAME);
			}

			if ((pos = strfind(data, "\"isp\":")) != -1)
			{
			    pos = pos + 7;

				strmid(isp, data, pos, strfind(data, "\"", true, pos), MAX_COUNTRY_NAME);
			}

			if (pos != -1)
			{
			    strpack(g_asLookupData[index][e_LookupCountry], country, MAX_COUNTRY_NAME char);
			    strpack(g_asLookupData[index][e_LookupRegion], region, MAX_COUNTRY_NAME char);
			    strpack(g_asLookupData[index][e_LookupCity], city, MAX_COUNTRY_NAME char);
			    strpack(g_asLookupData[index][e_LookupISP], isp, MAX_COUNTRY_NAME char);
				CallLocalFunction("OnLookupComplete", "dssss", index, country, region, city, isp);
			}
		}
	}
	return 0;
}
line 65 = CallLocalFunction("OnLookupComplete", "dssss", index, country, region, city, isp);


Re: IP Lookup Script - Banana_Ghost - 05.06.2016

Quote:
Originally Posted by muhsah007
Посмотреть сообщение
Код:
[02/06/2016 12:08:35] [join] xxxxxxx has joined the server (4:93.87.xxx.xxx)
[02/06/2016 12:08:35] [debug] Server crashed while executing GM.amx
[02/06/2016 12:08:35] [debug] AMX backtrace:
[02/06/2016 12:08:35] [debug] #0 native CallLocalFunction () from samp-server.exe
[02/06/2016 12:08:35] [debug] #1 000212b8 in public HTTP_OnLookupResponse (index=4, response=200, data[]=@007c125c "{"as":"AS8400 TELEKOM SRBIJA a.d.","city":"Belgrade","country":"Serbia","country...") at E:\Grand Theft Auto Server\pawno\include\ipl.inc:65
[02/06/2016 12:08:35] [debug] Native backtrace:
[02/06/2016 12:08:35] [debug] #0 0047467c in ?? () from samp-server.exe
[02/06/2016 12:08:35] [debug] #1 004010b6 in ?? () from samp-server.exe
[02/06/2016 12:08:35] [debug] #2 74e762ca in ?? () from plugins\crashdetect.dll
[02/06/2016 12:08:35] [debug] #3 74e78b28 in ?? () from plugins\crashdetect.dll
[02/06/2016 12:08:35] [debug] #4 74e709c7 in ?? () from plugins\crashdetect.dll
[02/06/2016 12:08:35] [debug] #5 74e7631a in ?? () from plugins\crashdetect.dll
[02/06/2016 12:08:35] [debug] #6 72c051b9 in ?? () from plugins\streamer.dll
[02/06/2016 12:08:35] [debug] #7 00480cd0 in ?? () from samp-server.exe
[02/06/2016 12:08:35] [debug] #8 004912c7 in ?? () from samp-server.exe
This include crashes my server whenever this player connects.
This is probably because the IP thats being passed has returned some sort of null data (some IPs may be missing a little bit of data). CallLocalFunction crashes if you pass a null string to it.

EDIT: just checked a random ip within the range in your message (93.87.22.22): the region name is empty, and thats what most likely causing it. I've made a fix for it below sorta.


Re: IP Lookup Script - Banana_Ghost - 05.06.2016

Updated the include.

Added support for Timezones and Zip Codes. - If you don't have the OnLookupComplete inside of your script, then the CallLocalFunction call to call OnLookupComplete will not be executed (it's not necessarily needed as there are functions to retrieve the data).

- Changed the OnLookupComplete to only pass the playerid, the functions of the include can be used to gather the information.


Re: IP Lookup Script - iLearner - 27.11.2016

Might be old, but i needed it. Tested: On windows it returns unknown(player is connect), on linux crashes server on startup.


Re: IP Lookup Script - GoldenMan - 29.08.2017

Код:
[18:26:41] [GoldenScripter] Has Joined The Server | [IP: [Hidden]] | [Country:Unknown] | [City: Unknown]
pls help its not showing Country And City

Код:
    //Connect With IP Country City
    GetPlayerCountry(playerid, Country, sizeof(Country));
    GetPlayerCity(playerid,City, sizeof(City));
    GetPlayerName(playerid, plname, sizeof(plname));
    GetPlayerIp(playerid, plip, sizeof(plip));
    format(connected,sizeof(connected),"[%s] Has Joined The Server | [IP: %s] | [Country:%s] | [City: %s]",plname,plip,Country,City);
    SendClientMessageToAll(COLOR_GREEN,connected);
using this code pls help me