<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java Source

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      14 Posts :: 24 Stories :: 8 Comments :: 0 Trackbacks
    去除0.0.0.255和0.0.0.0
    import java.net.Inet4Address;
    import java.net.InetAddress;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;

    /**
     * 
    @author justinlei (justinlei@gmail.com)
     * @date Nov 17, 2011
     * 
    @version 1.0
     
    */
    public class InetAddressUtil {
        
    public static void main(String[] args) throws Exception {
            Inet4Address start 
    = (Inet4Address)Inet4Address.getByName("172.20.0.254");
            Inet4Address end 
    = (Inet4Address)Inet4Address.getByName("172.20.10.1");
            List
    <byte[]> list = getRangeIps(null,start.getAddress(), end.getAddress());
            
    for (byte[] bs : list) {
                System.out.println(InetAddress.getByAddress(bs).getHostAddress());
            }
        }
        
        
    public static List<byte[]> getRangeIps(List<byte[]> list,byte[] addrBytes,byte[] endBytes) throws Exception {
            
    byte[] _b = new byte[addrBytes.length];
            System.arraycopy(addrBytes, 
    0, _b, 0, addrBytes.length);
            
    if(_b[3== -1)
                _b[
    3= -2;
            
    if(list == null) {
                list 
    = new ArrayList<byte[]>();
                list.add(_b);
            }
            
    if(list.size() == 5000)
                
    return list;
            
    if(addrBytes[2== -1 && addrBytes[3== -2)
                
    return list;
            
    if(Arrays.equals(addrBytes, endBytes)) {
                
    return list;
            }
            
    int lastpart = addrBytes[addrBytes.length - 1];
            
    if(lastpart != -2) {
                addrBytes[addrBytes.length 
    - 1= (byte)(addrBytes[3+ 1);
                _b 
    = new byte[addrBytes.length];
                System.arraycopy(addrBytes, 
    0, _b, 0, addrBytes.length);
                list.add(_b);
            } 
    else if(lastpart == -2) {
                addrBytes[addrBytes.length 
    - 1= 1;
                list.add(plus(addrBytes, addrBytes.length 
    - 2));
            }
    //        System.out.println(InetAddress.getByAddress(addrBytes).getHostAddress());
            return getRangeIps(list,addrBytes, endBytes);
        }
        
        
    public static byte[] plus(byte[] addrBytes,int index) throws Exception {
            
    if(index == 0)
                
    return addrBytes;
            
    int pluspart = addrBytes[index];
            
    if(pluspart != -2) {
                addrBytes[index] 
    = (byte)(pluspart + 1);
                
    for (int i = index + 1; i < addrBytes.length - 1; i++) {
                    addrBytes[i] 
    = 0;
                }
                
    byte[] _b = new byte[addrBytes.length];
                System.arraycopy(addrBytes, 
    0, _b, 0, addrBytes.length);
                
    return _b;
            } 
    else {
                
    byte[] _b = new byte[addrBytes.length];
                System.arraycopy(addrBytes, 
    0, _b, 0, addrBytes.length);
                
    return plus(_b, index -1);
            }
        }
    }
    posted on 2011-12-04 03:08 JustinLei 閱讀(471) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲av永久无码精品网站| 男男AV纯肉无码免费播放无码| mm1313亚洲国产精品美女| 久久久久亚洲国产| 成在人线AV无码免费| 亚洲精品动漫免费二区| 麻豆国产人免费人成免费视频 | 免费视频成人手机在线观看网址| 中文字幕无码精品亚洲资源网| 特级aa**毛片免费观看| 亚洲日韩中文无码久久| 免费看黄的成人APP| 亚洲毛片在线观看| 免费人成在线视频| 久久精品国产亚洲av瑜伽| 亚洲 国产 图片| a级日本高清免费看| 久久亚洲精品无码aⅴ大香| 久久久久久久免费视频| 亚洲AV成人精品一区二区三区| 又黄又大又爽免费视频| 国产性生大片免费观看性| 亚洲视频精品在线观看| 成人五级毛片免费播放| 免费一级全黄少妇性色生活片 | 亚洲综合一区二区三区四区五区 | 毛片高清视频在线看免费观看| 亚洲乱码中文字幕在线| 亚洲片国产一区一级在线观看| 三级网站在线免费观看| 91亚洲国产成人久久精品网址| 国产成人免费永久播放视频平台 | youjizz亚洲| 亚洲精品国产精品国自产观看 | 真实国产乱子伦精品免费| 中国亚洲呦女专区| 国产av无码专区亚洲av果冻传媒 | 亚洲午夜久久久久久噜噜噜| 中文字幕在线观看免费视频| 337p日本欧洲亚洲大胆人人| 亚洲国产精品一区第二页|