Skip to content

Commit

Permalink
Merge pull request #112 from xxxllluuu/master
Browse files Browse the repository at this point in the history
fix code conflict
  • Loading branch information
zxy0728 authored Dec 15, 2017
2 parents 6630b0e + 1abdc6c commit 8101826
Showing 1 changed file with 0 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,56 +221,6 @@ public static String getLocalIPByCL() {
return defaultLocalhostIp;
}

/*
* Try command line to get IP address
*/
public static String getLocalIPByCL() {

if (JVMToolHelper.isWindows()) {
return defaultLocalhostIp;
}

String ip = null;

String[] cmd = null;

Pattern pattern = Pattern.compile(IPREGEX);

String index = System.getProperty("NetCardIndex");

try {

if (!StringHelper.isEmpty(index)) {
int i = Integer.parseInt(index);
cmd = new String[] { "/bin/bash", "-c",
"ip route list|grep -Po 'src \\K[\\d.]+'|awk 'NR==" + (i + 1) + "'" };

ip = RuntimeHelper.exec(5000, cmd).trim();

if (!StringHelper.isEmpty(ip) && pattern.matcher(ip).matches() && !defaultLocalhostIp.equals(ip)) {
return ip;
}
}

String name = System.getProperty("NetCardName");

if (!StringHelper.isEmpty(name)) {
cmd = new String[] { "/bin/bash", "-c", "ip route list|grep " + name + "|grep -Po 'src \\K[\\d.]+'" };

ip = RuntimeHelper.exec(5000, cmd).trim();

if (!StringHelper.isEmpty(ip) && pattern.matcher(ip).matches() && !defaultLocalhostIp.equals(ip)) {
return ip;
}
}
}
catch (Exception e) {
// ignore
}

return defaultLocalhostIp;
}

public static boolean isIPV4(String ip) {

if (ip == null || ip.length() == 0)
Expand Down

0 comments on commit 8101826

Please sign in to comment.