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 閱讀(1146) 評論(1)  編輯  收藏

          評論

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

          lkj
          2013-02-05 14:47 | IPV6

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


          網站導航:
           
          主站蜘蛛池模板: 沙河市| 普兰店市| 潼南县| 昆山市| 隆化县| 桃江县| 马边| 通州市| 林州市| 南川市| 兴安县| 噶尔县| 从江县| 吕梁市| 化德县| 辽源市| 镇平县| 武陟县| 彭泽县| 晋城| 绥芬河市| 交城县| 若尔盖县| 崇州市| 平江县| 沈阳市| 乌兰县| 宾阳县| 保德县| 渭南市| 安庆市| 祁连县| 新建县| 昆明市| 保亭| 建平县| 信丰县| 洪江市| 井研县| 贵南县| 达尔|