File tree 3 files changed +44
-5
lines changed
3 files changed +44
-5
lines changed Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
1
+ Manifest-Version: 1.0
2
+ Main-Class: snailftp.App
Original file line number Diff line number Diff line change @@ -131,13 +131,20 @@ public static String formatTime(int second){
131
131
132
132
public static InetAddress getLocalAddress (){
133
133
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 ();
135
146
}catch (Exception exc ){
136
147
return null ;
137
148
}
138
149
}
139
-
140
- public static void main (String [] args ){
141
- System .out .println (Util .getLocalAddress ());
142
- }
143
150
}
You can’t perform that action at this time.
0 commit comments