Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7b373b66
authored
Oct 24, 2018
by
许雪里
Committed by
GitHub
Oct 24, 2018
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge pull request #557 from youbeiwuhuan/master
IpUtil获取本地地址的bug
parents
aa149427
75b5cceb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
xxl-job-core/src/main/java/com/xxl/job/core/util/IpUtil.java
xxl-job-core/src/main/java/com/xxl/job/core/util/IpUtil.java
View file @
7b373b66
package
com
.
xxl
.
job
.
core
.
util
;
package
com
.
xxl
.
job
.
core
.
util
;
import
org.slf4j.Logger
;
import
java.net.Inet6Address
;
import
org.slf4j.LoggerFactory
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
/**
* get ip
* get ip
* @author xuxueli 2016-5-22 11:38:05
* @author xuxueli 2016-5-22 11:38:05
...
@@ -42,15 +45,6 @@ public class IpUtil {
...
@@ -42,15 +45,6 @@ public class IpUtil {
* @return
* @return
*/
*/
private
static
InetAddress
getFirstValidAddress
()
{
private
static
InetAddress
getFirstValidAddress
()
{
InetAddress
localAddress
=
null
;
try
{
localAddress
=
InetAddress
.
getLocalHost
();
if
(
isValidAddress
(
localAddress
))
{
return
localAddress
;
}
}
catch
(
Throwable
e
)
{
logger
.
error
(
"Failed to retriving ip address, "
+
e
.
getMessage
(),
e
);
}
try
{
try
{
Enumeration
<
NetworkInterface
>
interfaces
=
NetworkInterface
.
getNetworkInterfaces
();
Enumeration
<
NetworkInterface
>
interfaces
=
NetworkInterface
.
getNetworkInterfaces
();
if
(
interfaces
!=
null
)
{
if
(
interfaces
!=
null
)
{
...
@@ -78,9 +72,22 @@ public class IpUtil {
...
@@ -78,9 +72,22 @@ public class IpUtil {
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
logger
.
error
(
"Failed to retriving ip address, "
+
e
.
getMessage
(),
e
);
logger
.
error
(
"Failed to retriving ip address, "
+
e
.
getMessage
(),
e
);
}
}
InetAddress
localAddress
=
null
;
try
{
localAddress
=
InetAddress
.
getLocalHost
();
if
(
isValidAddress
(
localAddress
))
{
return
localAddress
;
}
}
catch
(
Throwable
e
)
{
logger
.
error
(
"Failed to retriving ip address, "
+
e
.
getMessage
(),
e
);
}
logger
.
error
(
"Could not get local host ip address, will use 127.0.0.1 instead."
);
logger
.
error
(
"Could not get local host ip address, will use 127.0.0.1 instead."
);
return
localAddress
;
return
localAddress
;
}
}
/**
/**
* get address
* get address
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment