How to Reset Network Adapter in Ubuntu

Here’s a quick tip on how to reset your network adapter. This could come in handy if a server has an incorrect ip address and requires a reset to obtain the right ip address.

Simply run the following command:

sudo service network-manager restart

Reference

How do I reset the network adapter using a terminal command?. askubuntu. http://askubuntu.com/questions/54710/how-do-i-reset-the-network-adapter-using-a-terminal-command [04/12/2016].

How to check if an ip address matches a CIDR

When working in the area of application security, you may come across situations where you need to make sure that only certain servers are allowed to access your web service. Usually checking the ip address is a decent way of making such guarantees.

You can use a function as follows:

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

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

    return false;
}

Example results

cidr_match("1.2.3.4", "0.0.0.0/0"): true
cidr_match("127.0.0.1", "127.0.0.1/32"): true
cidr_match("127.0.0.1", "127.0.0.2/32"): false

Sources:

http://www.php.net/manual/en/function.ip2long.php#82397

http://stackoverflow.com/questions/594112/matching-an-ip-to-a-cidr-mask-in-php5