Java IP Address to Byte Array ipv4ToBinary(String ip)

Here you can find the source of ipv4ToBinary(String ip)

Description

ipv To Binary

License

Apache License

Declaration

public static byte[] ipv4ToBinary(String ip) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;

public class Main {
    public static byte[] ipv4ToBinary(String ip) {
        try {/*from w  w  w .  j a va 2  s  .c  o  m*/
            return InetAddress.getByName(ip).getAddress();
        } catch (Exception e) {
            return new byte[4];
        }
    }
}

Related

  1. ipToByte(String ip)
  2. ipToByte(String ip)
  3. IpToBytes(String ip)
  4. ipToBytesByReg(String ipAddr)
  5. ipv4StringToByteArrayUnchecked(String str)
  6. ipv4ToBytes(String ipv4)
  7. ipv4ToBytes(String ipv4)