1 | static void printMyIPs() {
|
2 | String ip; |
3 | try {
|
4 | Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); |
5 | while (interfaces.hasMoreElements()) {
|
6 | NetworkInterface iface = interfaces.nextElement(); |
7 | // filters out 127.0.0.1 and inactive interfaces |
8 | if (iface.isLoopback() || !iface.isUp()) |
9 | continue; |
10 | |
11 | Enumeration<InetAddress> addresses = iface.getInetAddresses(); |
12 | while(addresses.hasMoreElements()) {
|
13 | InetAddress addr = addresses.nextElement(); |
14 | ip = addr.getHostAddress(); |
15 | if (ip.startsWith("127.")) continue;
|
16 | boolean local = addr.isSiteLocalAddress() || ip.startsWith("fe");
|
17 | System.out.println(iface.getDisplayName() + " " + ip + " " + (local ? "(private address)" : "(public address)")); |
18 | } |
19 | } |
20 | } catch (Throwable e) {
|
21 | e.printStackTrace(); |
22 | } |
23 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000841 |
| Snippet name: | printMyIPs |
| Eternal ID of this version: | #1000841/1 |
| Text MD5: | 5debd7d4dfdb19a1446d6d5c0862569e |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-29 23:34:52 |
| Source code size: | 928 bytes / 23 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 1044 / 4379 |
| Referenced in: | [show references] |