2

次のコード:

InetAddress localHost = Inet4Address.getLocalHost();
NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);

for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
    System.out.println(address.getAddress() + "/" + address.getNetworkPrefixLength());
}

戻り値:

/fe80:0:0:0:11da:433a:412a:8c23%13/64
/192.168.1.107/128

私のサブネットマスクは/128ではなく/24です。Javaのバグですか?

4

3 に答える 3

7

たぶんあなたはこのバグにぶつかったでしょう:http: //bugs.sun.com/view_bug.do? bug_id = 6707289

(賛成するのをやめてください...これはたった1グーグル離れていました...)

于 2011-07-12T14:36:57.637 に答える
2

少なくとも私には意味がありません... /128IP4ネットワークには有効ではありません/32(最も高い(そして最も役に立たない;))値であり、ネットワークマスクのように単一のアドレスを持つネットワークを記述します255.255.255.255)。

/128アドレスが1つだけのネットワークであるIP6(= 128ビットの固定プレフィックス)でも同じです。

于 2011-07-12T14:40:01.877 に答える
1

情報ベースに追加すると、以下のipconfig出力で、jdk 1.8 /windows8.1で奇妙なprexixの長さが得られます。

length and ip4 interface address: 24, /192.168.1.104/24 [/192.168.1.255]
length and strange interface address: 64, /fe80:0:0:0:a162:16a3:1dc7:4f98%eth1/64 [null]
length and ip6 interface address: 128, /fe80:0:0:0:0:5efe:c0a8:168%net0/128 [null]
length and ip6 interface address: 128, /fe80:0:0:0:0:5efe:c0a8:12%net1/128 [null]
length and strange interface address: 64, /fe80:0:0:0:8190:5432:56a8:c006%wlan2/64 [null]
length and strange interface address: 64, /fe80:0:0:0:191c:bc6:985d:c0be%wlan3/64 [null]
length and strange interface address: 64, /fe80:0:0:0:29f9:1ede:602f:4530%wlan4/64 [null]
length and strange interface address: 0, /2001:0:5ef5:79fb:3c9f:4a:b354:8e66/0 [null]
length and strange interface address: 32, /fe80:0:0:0:3c9f:4a:b354:8e66%net2/32 [null]
length and strange interface address: 64, /fe80:0:0:0:181f:6633:5212:2f82%eth2/64 [null]
length and strange interface address: 64, /fe80:0:0:0:5df5:554b:5188:d070%eth3/64 [null]
length and ip4 interface address: 24, /192.168.0.18/24 [/192.168.0.255]
length and strange interface address: 64, /fe80:0:0:0:e828:e682:6a93:296d%wlan5/64 [null]



Windows IP Configuration


Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::e828:e682:6a93:296d%14
   IPv4 Address. . . . . . . . . . . : 192.168.0.18
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1

Ethernet adapter Ethernet 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

Ethernet adapter Ethernet 3:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

Wireless LAN adapter Local Area Connection* 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

Wireless LAN adapter Local Area Connection* 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

Wireless LAN adapter Wi-Fi 3:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : socal.rr.com
   Link-local IPv6 Address . . . . . : fe80::a162:16a3:1dc7:4f98%3
   IPv4 Address. . . . . . . . . . . : 192.168.1.104
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

Tunnel adapter isatap.{3ABD909F-0B6E-4DDB-AF74-1B3A98B48A56}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

Tunnel adapter isatap.socal.rr.com:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : socal.rr.com

Tunnel adapter Teredo Tunneling Pseudo-Interface:

   Connection-specific DNS Suffix  . : 
   IPv6 Address. . . . . . . . . . . : 2001:0:5ef5:79fb:3c9f:4a:b354:8e66
   Link-local IPv6 Address . . . . . : fe80::3c9f:4a:b354:8e66%11
   Default Gateway . . . . . . . . . : ::
于 2017-03-24T20:08:50.167 に答える