Here you can find the source of isPrivateNetworkAddress(final InetAddress inetAddress)
Parameter | Description |
---|---|
inetAddress | the given internet address |
public static boolean isPrivateNetworkAddress(final InetAddress inetAddress)
//package com.java2s; /*//from w ww . jav a 2 s.c om * NetworkUtils.java * * Created on Jan 12, 2010, 9:17:04 AM * * Description: NetworkUtils utilities. * * Copyright (C) Jan 12, 2010 reed. * * This program is free software; you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; * if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ import java.net.InetAddress; public class Main { /** Returns whether the given internet address is reserved for private networks, such as those behind a NAT router. * * @param inetAddress the given internet address * @return whether the given internet address is reserved for private networks */ public static boolean isPrivateNetworkAddress(final InetAddress inetAddress) { //Preconditions assert inetAddress != null : "inetAddress must not be null"; final String inetAddressString = inetAddress.getHostAddress(); return inetAddressString.startsWith("192.168.") || inetAddressString.startsWith("10.") || inetAddressString.startsWith("172."); } }