Created
January 19, 2015 01:32
-
-
Save darkwave/cc1f562b499d1f0c9d54 to your computer and use it in GitHub Desktop.
Get IP Address using native Java in Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.net.*; | |
void setup() { | |
try { | |
Enumeration e = NetworkInterface.getNetworkInterfaces(); | |
while (e.hasMoreElements ()) | |
{ | |
NetworkInterface n = (NetworkInterface) e.nextElement(); | |
Enumeration ee = n.getInetAddresses(); | |
while (ee.hasMoreElements ()) | |
{ | |
InetAddress i = (InetAddress) ee.nextElement(); | |
String ipAddress = i.getHostAddress(); | |
String[] ips = split(ipAddress, '.'); | |
if (ipAddress.indexOf("127.") != 0 && ipAddress.indexOf(":") < 0 | |
&& !ips[3].equals("1") // linux virtual ip quick fix | |
) { | |
println(ipAddress); | |
} | |
} | |
} | |
}catch (Exception ex) { | |
println("AH"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment