Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

19
LINES

< > BotCompany Repo | #1001181 // getMyIPs

JavaX fragment (include)

static L<S> getMyIPs() ctex {
  new TreeSet<S> ips;
  Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
  while (interfaces.hasMoreElements()) {
    NetworkInterface iface = interfaces.nextElement();
    // filters out 127.0.0.1 and inactive interfaces
    if (iface.isLoopback() || !iface.isUp())
        continue;

    Enumeration<InetAddress> addresses = iface.getInetAddresses();
    while(addresses.hasMoreElements()) {
      InetAddress addr = addresses.nextElement();
      S ip = addr.getHostAddress();
      if (ip.startsWith("127.")) continue;
      ips.add(ip);
    }
  }
  return new ArrayList<S>(ips);
}

Author comment

Began life as a copy of #1000841

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, snaazhdonpnp, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001181
Snippet name: getMyIPs
Eternal ID of this version: #1001181/1
Text MD5: d8c816d9af0b3760cc54a39b238829dc
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-28 18:23:45
Source code size: 668 bytes / 19 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 697 / 1016
Referenced in: [show references]