0% found this document useful (0 votes)
57 views1 page

Import Import Import Import Public Class Try: Local Ni Local Ni

This Java code snippet uses InetAddress and NetworkInterface classes to get the network interface associated with the local loopback address 127.0.0.1. It first gets the InetAddress object for 127.0.0.1, then uses that to call NetworkInterface's getByInetAddress method to retrieve the interface, printing an error if no interface is found. It catches potential SocketException and UnknownHostException errors from the network operations.

Uploaded by

Treymax Sikan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views1 page

Import Import Import Import Public Class Try: Local Ni Local Ni

This Java code snippet uses InetAddress and NetworkInterface classes to get the network interface associated with the local loopback address 127.0.0.1. It first gets the InetAddress object for 127.0.0.1, then uses that to call NetworkInterface's getByInetAddress method to retrieve the interface, printing an error if no interface is found. It catches potential SocketException and UnknownHostException errors from the network operations.

Uploaded by

Treymax Sikan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.net.

InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;

public class getByInetAddress { {

try {
InetAddress local =
InetAddress.getByName("127.0.0.1");
NetworkInterface ni =
NetworkInterface.getByInetAddress(local);
if (ni == null) {
System.err.println("That's weird. No local
loopback address.");
}
}
catch (SocketException ex) {
System.err.println("Could not list network
interfaces." );
} catch (UnknownHostException ex1) {
System.err.println("That's weird. Could not
lookup 127.0.0.1.");
}
}
}

You might also like