Java IP Address to Byte Array IpToBytes(String ip)

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

Description

Ip To Bytes

License

Open Source License

Declaration

static byte[] IpToBytes(String ip) 

Method Source Code

//package com.java2s;
/*//  w  w w  .  j ava2 s  .  c o  m
 * Copyright (c) 2014 ConteXtream Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    static byte[] IpToBytes(String ip) {
        String[] ipStr = ip.split("\\.");
        byte[] bytes = new byte[ipStr.length];
        for (int i = 0; i < ipStr.length; i++) {
            bytes[i] = Integer.valueOf(ipStr[i], 10).byteValue();
        }
        return bytes;
    }
}

Related

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