SA-MP Forums Archive
CHECK DYNAMIC IP FUNCTION? - 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: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: CHECK DYNAMIC IP FUNCTION? (/showthread.php?tid=533569)



CHECK DYNAMIC IP FUNCTION? - nGen.SoNNy - 25.08.2014

Hello guys, i want to edit my ban system using "gpci".

NAME: Test, IP: 122.122.122.555, SERIAL: 4084DADD58D44E0DED884D4FE4ECEED5D04CEE84

NAME: Test2, IP: 122.122.122.777, SERIAL: 4084DADD58D44E0DED884D4FE4ECEED5D04CEE84

So i need a function to detect if these two IPs are in the same range but i don't have any ideas right now. In my mind i have something like if( 122.122.122.*** == 122.122.122.*** ) => check if( SERIAL1 == SERIAL2 ) => KICK.

I would try the strfind with the "position" but some IPs have this format: **.***.**.*** or ***.***.**.*** so i can't use this way. (I'm using MySQL)

EDIT: Can i use something like
pawn Код:
SELECT * FROM `Banlist` WHERE `IP` LIKE '%127.0.0.1%'
?


Re: CHECK DYNAMIC IP FUNCTION? - Thogy - 25.08.2014

To compare two things is a function strcmp.

pawn Код:
new Test[16] = "122.122.122.555";
new Test2[16];

for(new i=0; i<1000; i++)
{
format(Test2, 16, "122.122.122.%i", i);
if(strcmp(Test, Test2, true))
{
//IP's are same.
}
else
{
//IP's aren't same.
}
}



Re: CHECK DYNAMIC IP FUNCTION? - nGen.SoNNy - 25.08.2014

What if his IP will change like this: 122.122.***.*** ?


Re: CHECK DYNAMIC IP FUNCTION? - Thogy - 25.08.2014

pawn Код:
new TestPart1[12] = "122.122.122";
new TestPart2[16] = "122.122.122.555;
new Test2Part1[12], Test2Part2[16];

for(new i=0; i<1000; i++)
{
format(Test2Part1, 12, "
122.122.%i", i);
if(strcmp(TestPart1, Test2Part1, true))
{
//if IP's part1 are same.
for(new u=0; u<1000; u++)
{
format(Test2Part2, 16, "
122.122.%i.%i",i, u);
if(strcmp(TestPart2, Test2Part2, true))
{
//IP's part1+part2 are same - Kick
}
}
}
}



Re: CHECK DYNAMIC IP FUNCTION? - nGen.SoNNy - 25.08.2014

This check used on OnPLayerConnect... it's not a good ideea.


Re: CHECK DYNAMIC IP FUNCTION? - Khanz - 25.08.2014

Quote:
Originally Posted by nGen.SoNNy
Посмотреть сообщение
What if his IP will change like this: 122.122.***.*** ?
What is it's a player from the same country or multiple? That wouldn't be fair.


Re: CHECK DYNAMIC IP FUNCTION? - nGen.SoNNy - 25.08.2014

Idk but in my 5 years of activity.. i found "hackers" which can change their ip like that...


Re: CHECK DYNAMIC IP FUNCTION? - BornHuman - 25.08.2014

Just rangeban them.
https://sampforum.blast.hk/showthread.php?tid=381712


Re: CHECK DYNAMIC IP FUNCTION? - Pottus - 25.08.2014

Quote:
Originally Posted by BornHuman
Посмотреть сообщение
Rangeban is the absolute worst and ineffective ban method there is.

There is a couple of ways you could extract the range for checking.

sscanf()

pawn Код:
new ip1, ip2;
sscanf(ip, "p<.>ii", ip1, ip2);
format(query, sizeof(query), "SELECT * FROM `Banlist` WHERE `IP` LIKE '%i.%i%%%%'", ip1, ip2);



Re: CHECK DYNAMIC IP FUNCTION? - Sithis - 26.08.2014

Quote:
Originally Posted by Thogy
Посмотреть сообщение
pawn Код:
new TestPart2[16] = "122.122.122.555;
Are you sure you know what you're doing?