liangoogle

          liangoogle
          隨筆 - 9, 文章 - 0, 評論 - 3, 引用 - 0
          數據加載中……

          查詢IP地址是IPV4還是IPV6,查詢IP的類別

          import java.net.*;
          import java.io.*;

          public class IPVersion {
          public static void main(String args[]) {
          try {
          InetAddress inetadd = InetAddress.getLocalHost();
          byte[] address = inetadd.getAddress();
          System.out.println(address);
          if (address.length == 4) {
          System.out.println("The ip version is ipv4");
          int firstbyte = address[0];
          if (firstbyte < 0)
          firstbyte += 256;
          if ((firstbyte & 0x80) == 0)
          System.out.println("the ip class is A");
          else if ((firstbyte & 0xC0) == 0x80)
          System.out.println("The ip class is B");
          else if ((firstbyte & 0xE0) == 0xC0)
          System.out.println("The ip class is C");
          else if ((firstbyte & 0xF0) == 0xE0)
          System.out.println("The ip class is D");
          else if ((firstbyte & 0xF8) == 0xF0)
          System.out.println("The ip class is E");
          } else if (address.length == 16)
          System.out.println("The ip version is ipv6");
          } catch (Exception e) {
          }
          ;
          }
          }

          posted on 2011-04-21 19:14 haojinlian 閱讀(1145) 評論(1)  編輯  收藏

          評論

          # re: 查詢IP地址是IPV4還是IPV6,查詢IP的類別  回復  更多評論   

          lkj
          2013-02-05 14:47 | IPV6

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


          網站導航:
           
          主站蜘蛛池模板: 葵青区| 中西区| 崇信县| 望都县| 九台市| 顺义区| 墨竹工卡县| 沈阳市| 柳州市| 阜宁县| 兴业县| 陇西县| 广昌县| 新干县| 临清市| 申扎县| 乌鲁木齐市| 台州市| 五大连池市| 翁源县| 贵港市| 合肥市| 大兴区| 绥宁县| 确山县| 五台县| 轮台县| 东安县| 军事| 会东县| 阜南县| 温宿县| 沂源县| 眉山市| 拜泉县| 安远县| 丹寨县| 长武县| 隆林| 大姚县| 亚东县|