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

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


          網站導航:
           
          主站蜘蛛池模板: 凤冈县| 古田县| 龙山县| 墨脱县| 勃利县| 南川市| 冀州市| 汶川县| 沙雅县| 阿鲁科尔沁旗| 云林县| 寻甸| 类乌齐县| 鄢陵县| 南陵县| 黄山市| 洪洞县| 成安县| 八宿县| 邹城市| 望奎县| 新源县| 宜州市| 新郑市| 平泉县| 青海省| 蓬溪县| 太仆寺旗| 荃湾区| 九江市| 左贡县| 佛教| 珠海市| 长顺县| 广宁县| 孟连| 乌拉特后旗| 兴文县| 陕西省| 吴旗县| 永清县|