Detect "range ips" with GetPlayerIP.
#1

Hey,

I'm wondering, is it possible to detect range IPs with GetPlayerIP?
For example:
pawn Код:
new pIp[16];
GetPlayerIp(playerid, pIp, sizeof(pIp));
if(strcmp(pip,  "76.138.*.*", true) == 0)
I can't test it at this moment, so I'd like to ask it on this forum. I assume it's not possible, but you could always give it a shot.
This would be very useful if you rangeban someone and you'd like to create an exception for a specific IP.

Thanks.
Reply
#2

That wont work, since your comparing it into a string

example: if my ip is 123.123.123.123
if will check if "123.123.123.123" is equal to "123.123.*.*", it isnt equal due to the stars so wont detect the player.

You will have to split the part of the player's ip, and the part of the banned IP (to get only the first two parts) and compare those!
Reply
#3

I didn't mean that code will work, I meant something similair to that.
So, the only way to find the first few digits of an IP would be:
pawn Код:
new pip[5];
GetPlayerIp(playerid, pip, sizeof(pip));
if(!strcmp(pip, "127.0"))
Reply
#4

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
I didn't mean that code will work, I meant something similair to that.
So, the only way to find the first few digits of an IP would be:
pawn Код:
new pip[5];
GetPlayerIp(playerid, pip, sizeof(pip));
if(!strcmp(pip, "127.0"))
A single strcmp will not work IMO.
Don't think of using the "length" parameter in strcmp, or getting the first few digits of the IP, because the length of IPs are different.
If you try to get first 5 characters of the IP then it may get something like "11.12","111.2",
while their actual IP is "11.123.200.1","111.213.65.30",etc..

To check it you have to split the values into four and check them:
pawn Код:
new IP[4],IPString[16];
GetPlayerIp(playerid,IPString,sizeof(IPString));
sscanf(IPString,"p<.>a<i>[4]",IP);
if(IP[0] == 127 && IP[1] == 0) Ban(playerid);//Player's IP matches 127.0.*.*
Reply
#5

Quote:
Originally Posted by leong124
Посмотреть сообщение
A single strcmp will not work IMO.
Don't think of using the "length" parameter in strcmp, or getting the first few digits of the IP, because the length of IPs are different.
If you try to get first 5 characters of the IP then it may get something like "11.12","111.2",
while their actual IP is "11.123.200.1","111.213.65.30",etc..
Not bad, thank you for explaining.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)