Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.apache.http.conn.util.InetAddressUtils;
import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    static public boolean isValidIpAddress(String ip) {
        boolean v4 = InetAddressUtils.isIPv4Address(ip);
        boolean v6 = InetAddressUtils.isIPv6Address(ip);
        if (!v4 && !v6)
            return false;
        try {
            InetAddress inet = InetAddress.getByName(ip);
            return inet.isLinkLocalAddress() || inet.isSiteLocalAddress();
        } catch (UnknownHostException e) {
            //Log.e(TAG, e.toString());
            return false;
        }
    }
}