org.clazzes.util.net
Class NetUtil

java.lang.Object
  extended by org.clazzes.util.net.NetUtil

public class NetUtil
extends java.lang.Object

Author:
lech

Method Summary
static java.lang.String ipLong2String(long nr)
          Take a long representing an IPv4 address and converts it to a printable string
static long ipString2Long(java.lang.String ip)
          Parses a string containing a dotted IPv4 address and converts it to a long.
static boolean isValidIPv4(java.lang.String ip)
          Checks if a string contains (only) a valid IPv4 address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

ipString2Long

public static long ipString2Long(java.lang.String ip)
Parses a string containing a dotted IPv4 address and converts it to a long. Does no checks of any kind, use isValidIPv4 for that!

Parameters:
ip - The string containing the IPv4 address, e.g. "1.2.3.4"
Returns:
the long containing the address, e.g. 0x01020304

ipLong2String

public static java.lang.String ipLong2String(long nr)
Take a long representing an IPv4 address and converts it to a printable string

Parameters:
nr - the long containing the address, e.g. 0x01020304
Returns:
The string containing the IPv4 address, e.g. "1.2.3.4"

isValidIPv4

public static boolean isValidIPv4(java.lang.String ip)
Checks if a string contains (only) a valid IPv4 address. Does not check detail like zero subnets, only if syntax is ok and values are in range 0-255.0-255.0-255.0-255

Parameters:
ip - Suspect string to check
Returns:
if the given string looks like a valid IPv4 address


Copyright © 2010. All Rights Reserved.