SA-MP Forums Archive
IP detection code - 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: IP detection code (/showthread.php?tid=609936)



IP detection code - NeXoR - 18.06.2016

Would this code work ?

PHP код:
stock IsIP(ip[], size=sizeof(ip))
{
    new 
dots 0nums 0other 0;
    for(
0sizei++)
    {
        switch(
ip[i])
        {
            case 
'.':
            {
                
dots++;
            }
            case 
'0'..'9':
            {
                 
nums++;
            }
            default:
            {
                
other++;
            }
        }
    }
    if(
dots || nums 12 || other != 0) return 0;
    else return 
1;




Re: IP detection code - DTV - 18.06.2016

You could try it, although what would be the purpose of you using this?


Re: IP detection code - Beckett - 18.06.2016

Work for what precisely?


Re: IP detection code - Vince - 18.06.2016

It would detect something like 999.999.999.999, which is not a valid IP. The following is a bit more precise:

PHP код:
bool:IsIP(string[])
{
    new 
parts[4];
    
    if(
sscanf(string"p<.>a<i>[4]"parts))
        return 
false;
        
    for(new 
isizeof(parts); i++)
    {
        if(!(
<= part[i] <= 255))
            return 
false;
    }
    
    return 
true;

Although a regular expression is better still since it can locate them within other text.


Re: IP detection code - xTURBOx - 18.06.2016

https://github.com/Kar2k/samp-anti-a...dvertising.inc
made by Kar