Mercurial Hosting > luan
comparison core/src/luan/modules/IoLuan.java @ 735:2486fa6490c6
add Io.my_ips()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 14 Jun 2016 18:24:28 -0600 |
parents | e44e98fe9de8 |
children | f8a7cc1fd3f6 |
comparison
equal
deleted
inserted
replaced
734:e44e98fe9de8 | 735:2486fa6490c6 |
---|---|
23 import java.io.FileNotFoundException; | 23 import java.io.FileNotFoundException; |
24 import java.net.URL; | 24 import java.net.URL; |
25 import java.net.Socket; | 25 import java.net.Socket; |
26 import java.net.ServerSocket; | 26 import java.net.ServerSocket; |
27 import java.net.InetAddress; | 27 import java.net.InetAddress; |
28 import java.net.Inet4Address; | |
29 import java.net.NetworkInterface; | |
28 import java.net.MalformedURLException; | 30 import java.net.MalformedURLException; |
29 import java.net.UnknownHostException; | 31 import java.net.UnknownHostException; |
32 import java.util.Enumeration; | |
30 import java.util.Map; | 33 import java.util.Map; |
31 import java.util.zip.ZipOutputStream; | 34 import java.util.zip.ZipOutputStream; |
32 import java.util.zip.ZipEntry; | 35 import java.util.zip.ZipEntry; |
33 import luan.Luan; | 36 import luan.Luan; |
34 import luan.LuanState; | 37 import luan.LuanState; |
742 try { | 745 try { |
743 return InetAddress.getByName(domain).getHostAddress(); | 746 return InetAddress.getByName(domain).getHostAddress(); |
744 } catch(UnknownHostException e) { | 747 } catch(UnknownHostException e) { |
745 return null; | 748 return null; |
746 } | 749 } |
750 } | |
751 | |
752 public static LuanTable my_ips() throws IOException { | |
753 LuanTable tbl = new LuanTable(); | |
754 for( Enumeration<NetworkInterface> e1 = NetworkInterface.getNetworkInterfaces(); e1.hasMoreElements(); ) { | |
755 NetworkInterface ni = e1.nextElement(); | |
756 for( Enumeration<InetAddress> e2 = ni.getInetAddresses(); e2.hasMoreElements(); ) { | |
757 InetAddress ia = e2.nextElement(); | |
758 if( ia instanceof Inet4Address ) | |
759 tbl.rawPut(ia.getHostAddress(),true); | |
760 } | |
761 } | |
762 return tbl; | |
747 } | 763 } |
748 | 764 |
749 | 765 |
750 // files maps zip name to uri | 766 // files maps zip name to uri |
751 public static void zip(LuanState luan,String zipUri,LuanTable files) throws LuanException, IOException { | 767 public static void zip(LuanState luan,String zipUri,LuanTable files) throws LuanException, IOException { |