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

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


          網站導航:
           
          主站蜘蛛池模板: 大渡口区| 札达县| 渝北区| 彰化市| 乐至县| 和龙市| 大姚县| 山东省| 若尔盖县| 张北县| 颍上县| 六安市| 铜山县| 南乐县| 德兴市| 连江县| 郁南县| 泰和县| 姜堰市| 克拉玛依市| 普宁市| 梅河口市| 哈巴河县| 旬邑县| 五常市| 昆明市| 乌兰浩特市| 阿坝| 茂名市| 宜丰县| 余庆县| 屯门区| 伊春市| 枣阳市| 东港市| 宣城市| 新干县| 高青县| 平和县| 句容市| 鄂伦春自治旗|