/**
* Copyright (C) 2009 Nortel, certain elements licensed under a Contributor Agreement.
* Contributors retain copyright to elements licensed under a Contributor Agreement.
* Licensed to the User under the LGPL license.
*/
//package com.nowjava;
//时 代 J a v a 公 众 号 - N o w J a v a . c o m 提供
public class Main {
public static void main(String[] argv) throws Exception {
String address = "nowjava.com";
System.out.println(isLiteralIPAddress(address));
}
/**
* Test to see if the given address string represents a literal IPv4 address.
*
* @param address
* The address string to be tested.
*
* @return
* True if literal IPv4 address, False otherwise.
*/
public static boolean isLiteralIPAddress(String address) {
String[] octets = address.split("\\.", -1);
if (octets.length != 4) {
return false;
}
/*来 自 N o w J a v a . c o m*/
for (int i = 0; i < 4; i++) {
int octetValue = -1;
try {
octetValue = Integer.parseInt(octets[i]);
} catch (NumberFormatException e) {
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。