Skip to content

Instantly share code, notes, and snippets.

@darkwave
Created January 19, 2015 01:32
Show Gist options
  • Save darkwave/cc1f562b499d1f0c9d54 to your computer and use it in GitHub Desktop.
Save darkwave/cc1f562b499d1f0c9d54 to your computer and use it in GitHub Desktop.
Get IP Address using native Java in Processing
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