• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] how to get the last digit of a player's IP
#12
(2021-07-16, 07:14 PM)Kwarde Wrote: Then you are still doing something wrong.
Code:
#include <a_samp>
#include <sscanf2>

main()
{
    new
        IP_LAN[] = "192.168.1.69",
        IP_PUBLIC[] = "86.88.190.219",
        
        ip_lan_part[4], ip_public_part[4]
    ;
    sscanf(IP_LAN, "p<.>dddd", ip_lan_part[0], ip_lan_part[1], ip_lan_part[2], ip_lan_part[3]);
    sscanf(IP_PUBLIC, "p<.>dddd", ip_public_part[0], ip_public_part[1], ip_public_part[2], ip_public_part[3]);

    if (ip_lan_part[0] == 192 && ip_lan_part[1] == 168 && ip_lan_part[2] == 1 && (1 <= ip_lan_part[3] <= 255))
    {
        print("IP_LAN: Is accepted LAN");
    }
    else
    {
        print("IP_LAN: Is NOT accepted LAN");
    }

    if (ip_public_part[0] == 192 && ip_public_part[1] == 168 && ip_public_part[2] == 1 && (1 <= ip_public_part[3] <= 255))
    {
        print("IP_PUBLIC: Is accepted LAN");
    }
    else
    {
        print("IP_PUBLIC: Is NOT accepted LAN");
    }
}

100% guaranteed that the output is:
Quote:IP_LAN: Is accepted LAN
IP_PUBLIC: Is NOT accepted LAN

i believe the way to fix this is to compare the player's ip and the target ip by somehow replacing
Code:
IP_PUBLIC[] = "86.88.190.219",
with the player's ip. is it possible? because that's what i'm trying to do right now

edit: and no my public server is hosted by ultra-h for quick tests you know

edit 2: to remind you what im trying to do is to somehow compare the player's ip with the specific ip (192.168.1.4) for example. what you've done so far is compare a specific ip with another specific ip to see if they match which is not what i really want. i hope you understand what im saying. another idea i just thought of while making this edit is to somehow use range values like in Kotlin where you simply do:
Code:
1..10
is that also possible, any library for that?
  Reply


Messages In This Thread
RE: how to get the last digit of a player's IP - by mems - 2021-07-16, 07:19 PM

Forum Jump: