Changed local ip detection to use regex
This commit is contained in:
@@ -18,6 +18,7 @@ import java.net.NetworkInterface;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Creates an Http connection that hosts a game
|
||||
@@ -39,11 +40,12 @@ public class HttpMatchBrowserHost extends Thread {
|
||||
httpClient = HttpClients.createDefault();
|
||||
|
||||
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
|
||||
int count = 0;
|
||||
boolean matches = false;
|
||||
String ip = "";
|
||||
Pattern ipPattern = Pattern.compile("192.168.1.*");
|
||||
while(e.hasMoreElements())
|
||||
{
|
||||
if (count > 3){
|
||||
if (matches){
|
||||
break;
|
||||
}
|
||||
NetworkInterface n = (NetworkInterface) e.nextElement();
|
||||
@@ -51,13 +53,12 @@ public class HttpMatchBrowserHost extends Thread {
|
||||
while (ee.hasMoreElements())
|
||||
{
|
||||
InetAddress i = ee.nextElement();
|
||||
if (count == 3){
|
||||
matches = ipPattern.matcher(i.getHostAddress()).matches();
|
||||
if (matches){
|
||||
ip = i.getHostAddress();
|
||||
//System.out.println(ip);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user