Java IP Address to Int ipV4ToInt(String addr)

Here you can find the source of ipV4ToInt(String addr)

Description

ip V To Int

License

Open Source License

Declaration

public static int ipV4ToInt(String addr) 

Method Source Code

//package com.java2s;
/*//  w  w  w . j  a v  a2  s.  c  o  m
    
Copyright (C) 2011 NTT DATA Corporation
    
This program is free software; you can redistribute it and/or
Modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
    
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU General Public License for more details.
    
 */

public class Main {

    public static int ipV4ToInt(String addr) {
        int[] ary = new int[4];
        String[] strAry = addr.split("\\.");

        for (int i = 0; i < 4; i++) {
            ary[i] = Integer.parseInt(strAry[i]);
        }

        int l = ary[0] << 24;
        l += ary[1] << 16;
        l += ary[2] << 8;
        l += ary[3];

        return l;
    }
}

Related

  1. ipToInt(String ipAddr)
  2. IpToInt(String strIp)
  3. ipToInteger(String ip)
  4. IPV4AddressStrToInteger(String ipAddressStr)
  5. IPV4AddressToInteger(byte[] addr)
  6. ipv4ToInt(String addr)
  7. ipv4ToInt(String address)