| | |
| | | * @return 广播地址
|
| | | */
|
| | | public static String getBroadcastAddress() {
|
| | | try {
|
| | | for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces();
|
| | | niEnum.hasMoreElements(); ) {
|
| | | NetworkInterface ni = niEnum.nextElement();
|
| | | if (!ni.isLoopback()) {
|
| | | for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) {
|
| | | if (interfaceAddress.getBroadcast() != null) {
|
| | | return interfaceAddress.getBroadcast().toString().substring(1);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | } catch (SocketException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | // try {
|
| | | // for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces();
|
| | | // niEnum.hasMoreElements(); ) {
|
| | | // NetworkInterface ni = niEnum.nextElement();
|
| | | // if (!ni.isLoopback()) {
|
| | | // for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) {
|
| | | // if (interfaceAddress.getBroadcast() != null) {
|
| | | // return interfaceAddress.getBroadcast().toString().substring(1);
|
| | | // }
|
| | | // }
|
| | | // }
|
| | | // }
|
| | | // } catch (SocketException e) {
|
| | | // e.printStackTrace();
|
| | | // }
|
| | | return "255.255.255.255";
|
| | | }
|
| | |
|