查询是否为内网IP @param ip ip地址 @return
(String ip)
| 178 | * @return |
| 179 | */ |
| 180 | public static boolean isLocalIP(String ip){ |
| 181 | try { |
| 182 | InetAddress address = InetAddress.getByName(ip); |
| 183 | if(address.isSiteLocalAddress() || address.isLoopbackAddress()){//如果为内网IP |
| 184 | return true; |
| 185 | } |
| 186 | } catch (UnknownHostException e) { |
| 187 | // TODO Auto-generated catch block |
| 188 | //e1.printStackTrace(); |
| 189 | if (logger.isErrorEnabled()) { |
| 190 | logger.error("查询是否为内网IP错误",e); |
| 191 | } |
| 192 | } |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | |
| 197 |