P
P
Peter2015-03-04 12:44:18
Computer networks
Peter, 2015-03-04 12:44:18

What real IP will come from the subnet?

Good day to all!
I have a nodejs (or php, whatever) service. This service is requested from servers on the 31.131.xxx.x/25 or 46.182.xx.xxx/29 subnet. What IP will I receive in the code of my project? How can I calculate this IP from, for example, 31.131.xxx.x/25 or 46.182.xx.xxx/29?
My service hangs on a separate IP in none of these subnets.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2015-03-04
@petrostasuk

This function checks that the address is on a CIDR subnet:

function cidr_match($ip, $cidr)
{
    list($subnet, $mask) = explode('/', $cidr);

    if ((ip2long($ip) & ~((1 << (32 - $mask)) - 1) ) == ip2long($subnet))
    { 
        return true;
    }

    return false;
}

Original answer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question