IP detection code
#1

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;

Reply
#2

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

Work for what precisely?
Reply
#4

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.
Reply
#5

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


Forum Jump:


Users browsing this thread: 1 Guest(s)