-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndirizzi.java
47 lines (40 loc) · 1.23 KB
/
Indirizzi.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.Socket;
import java.net.InetSocketAddress;
import java.util.Arrays;
public class Indirizzi {
public static void print(Boolean flag, Object... s) {
for (Object o : s) {
System.out.print(o);
}
if (flag)
System.out.println();
else
System.out.print("");
}
public static void getByName(String name) throws UnknownHostException {
InetAddress ia = InetAddress.getByName(name);
byte[] ndp = ia.getAddress();
print(false, "Indirizzo: ");
for (byte b : ndp) {
print(false, b & 0xff, ".");
}
print(true);
}
public static void getAllByName(String name) throws UnknownHostException {
InetAddress[] iaa = InetAddress.getAllByName(name);
for (InetAddress ia : iaa) {
print(true, "Indirizzo: " + ia.getHostName() + " -> " + ia.getHostAddress());
}
}
public static void main(String[] args) {
String name = args[0];
try {
// getByName(name);
getAllByName(name);
} catch (UnknownHostException u) {
u.printStackTrace();
}
}
}