public static long convertToLong(String addr) throws Exception {
        String[] octs = addr.split("\\.");

        if( octs.length != 4 ){
            throw new Exception("Invalid address format.");
        }

        long octA = Long.parseLong(octs[0]);
        long octB = Long.parseLong(octs[1]);
        long octC = Long.parseLong(octs[2]);
        long octD = Long.parseLong(octs[3]);

        if( octA < 0 || 255 < octA ){
            throw new Exception("Invalid octet on 1st section.");
        }
        if( octB < 0 || 255 < octB ){
            throw new Exception("Invalid octet on 2nd section.");
        }
        if( octC < 0 || 255 < octC ){
            throw new Exception("Invalid octet on 3rd section.");
        }
        if( octD < 0 || 255 < octD ){
            throw new Exception("Invalid octet on 4th section.");
        }

        return (octA<<24) | (octB<<16) | (octC<<8) | octD;
    }