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