BOOKJAVA Telegram 4041
Определение и отличие IP адресов LAN, PPP в Java

Чтобы определить IP-адрес локальной машины с использованием Java, примените следующий код:


import java.net.*;

public class GetIP {
public static void main(String[] args) throws UnknownHostException {
System.out.println(InetAddress.getLocalHost().getHostAddress());
}
}


Работа с несколькими сетевыми интерфейсами

Если ваш компьютер оснащён несколькими сетевыми интерфейсами, иногда бывает необходимо обойти весь список интерфейсов и отфильтровать адреса, не являющиеся обратными петлями и являющиеся локальными для сайта. Это особенно актуально при работе в средах с многочисленными сетями.


import java.net.*;
import java.util.*;

public class GetMultiIPs {
public static void main(String[] args) throws SocketException {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface iface = interfaces.nextElement();
if (iface.isLoopback() || !iface.isUp()) continue;

Enumeration<InetAddress> addresses = iface.getInetAddresses();
while(addresses.hasMoreElements()) {
InetAddress addr = addresses.nextElement();
if (addr instanceof Inet4Address) {
System.out.println(iface.getDisplayName() + " – " + addr.getHostAddress());
}
}
}
}
}


Мы в MAX

👉@BookJava
1👍31



tgoop.com/BookJava/4041
Create:
Last Update:

Определение и отличие IP адресов LAN, PPP в Java

Чтобы определить IP-адрес локальной машины с использованием Java, примените следующий код:


import java.net.*;

public class GetIP {
public static void main(String[] args) throws UnknownHostException {
System.out.println(InetAddress.getLocalHost().getHostAddress());
}
}


Работа с несколькими сетевыми интерфейсами

Если ваш компьютер оснащён несколькими сетевыми интерфейсами, иногда бывает необходимо обойти весь список интерфейсов и отфильтровать адреса, не являющиеся обратными петлями и являющиеся локальными для сайта. Это особенно актуально при работе в средах с многочисленными сетями.


import java.net.*;
import java.util.*;

public class GetMultiIPs {
public static void main(String[] args) throws SocketException {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface iface = interfaces.nextElement();
if (iface.isLoopback() || !iface.isUp()) continue;

Enumeration<InetAddress> addresses = iface.getInetAddresses();
while(addresses.hasMoreElements()) {
InetAddress addr = addresses.nextElement();
if (addr instanceof Inet4Address) {
System.out.println(iface.getDisplayName() + " – " + addr.getHostAddress());
}
}
}
}
}


Мы в MAX

👉@BookJava

BY Библиотека Java разработчика




Share with your friend now:
tgoop.com/BookJava/4041

View MORE
Open in Telegram


Telegram News

Date: |

Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October. “Hey degen, are you stressed? Just let it all out,” he wrote, along with a link to join the group. It’s yet another bloodbath on Satoshi Street. As of press time, Bitcoin (BTC) and the broader cryptocurrency market have corrected another 10 percent amid a massive sell-off. Ethereum (EHT) is down a staggering 15 percent moving close to $1,000, down more than 42 percent on the weekly chart. As the broader market downturn continues, yelling online has become the crypto trader’s latest coping mechanism after the rise of Goblintown Ethereum NFTs at the end of May and beginning of June, where holders made incoherent groaning sounds and role-played as urine-loving goblin creatures in late-night Twitter Spaces. Channel login must contain 5-32 characters
from us


Telegram Библиотека Java разработчика
FROM American