Skip to content

Commit a638766

Browse files
author
jiangjizhong
committed
1 parent f5dfcb5 commit a638766

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

build.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<project name="snailftp" default="dist" basedir=".">
2+
<description>
3+
SnailFTP
4+
</description>
5+
6+
<property name="src" location="src"/>
7+
<property name="build" location="build"/>
8+
<property name="dist" location="dist"/>
9+
10+
<target name="init">
11+
<tstamp/>
12+
<mkdir dir="${build}"/>
13+
</target>
14+
15+
<target name="compile" depends="init"
16+
description="compile the source " >
17+
<javac srcdir="${src}" encoding="utf-8" destdir="${build}"/>
18+
</target>
19+
20+
<target name="dist" depends="compile"
21+
description="generate the distribution" >
22+
<jar jarfile="${dist}/lib/snailftp.jar" manifest="manifest.mf" basedir="${build}"/>
23+
</target>
24+
25+
<target name="clean"
26+
description="clean up" >
27+
<delete dir="${build}"/>
28+
<delete dir="${dist}"/>
29+
</target>
30+
</project>

manifest.mf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+
Main-Class: snailftp.App

src/snailftp/Util.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,20 @@ public static String formatTime(int second){
131131

132132
public static InetAddress getLocalAddress(){
133133
try{
134-
return InetAddress.getLocalHost();
134+
Enumeration<NetworkInterface> networkInterfaceEnumeration = NetworkInterface.getNetworkInterfaces();
135+
while (networkInterfaceEnumeration.hasMoreElements()) {
136+
NetworkInterface networkInterface = networkInterfaceEnumeration.nextElement();
137+
if(networkInterface.isLoopback() || !networkInterface.isUp()){
138+
continue;
139+
}
140+
Enumeration<InetAddress> inetAddressEnumeration = networkInterface.getInetAddresses();
141+
while(inetAddressEnumeration.hasMoreElements()){
142+
return inetAddressEnumeration.nextElement();
143+
}
144+
}
145+
return InetAddress.getLocalHost();
135146
}catch(Exception exc){
136147
return null;
137148
}
138149
}
139-
140-
public static void main(String[] args){
141-
System.out.println(Util.getLocalAddress());
142-
}
143150
}

0 commit comments

Comments
 (0)