(String ip)
| 58 | |
| 59 | //校验字符串是否是一个合格的IP地址 |
| 60 | public static boolean isValidIP (String ip) { |
| 61 | try { |
| 62 | if ( ip == null || ip.isEmpty() ) { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | String[] parts = ip.split( "\\." ); |
| 67 | if ( parts.length != 4 ) { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | for ( String s : parts ) { |
| 72 | int i = Integer.parseInt( s ); |
| 73 | if ( (i < 0) || (i > 255) ) { |
| 74 | return false; |
| 75 | } |
| 76 | } |
| 77 | if ( ip.endsWith(".") ) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | return true; |
| 82 | } catch (NumberFormatException nfe) { |
| 83 | return false; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | @Deprecated |
| 88 | public static boolean isValidSubnet(String subnet) { |
no outgoing calls
no test coverage detected