Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/core/src/luan/modules/IoLuan.java Tue Jun 14 17:54:12 2016 -0600 +++ b/core/src/luan/modules/IoLuan.java Tue Jun 14 18:24:28 2016 -0600 @@ -25,8 +25,11 @@ import java.net.Socket; import java.net.ServerSocket; import java.net.InetAddress; +import java.net.Inet4Address; +import java.net.NetworkInterface; import java.net.MalformedURLException; import java.net.UnknownHostException; +import java.util.Enumeration; import java.util.Map; import java.util.zip.ZipOutputStream; import java.util.zip.ZipEntry; @@ -746,6 +749,19 @@ } } + public static LuanTable my_ips() throws IOException { + LuanTable tbl = new LuanTable(); + for( Enumeration<NetworkInterface> e1 = NetworkInterface.getNetworkInterfaces(); e1.hasMoreElements(); ) { + NetworkInterface ni = e1.nextElement(); + for( Enumeration<InetAddress> e2 = ni.getInetAddresses(); e2.hasMoreElements(); ) { + InetAddress ia = e2.nextElement(); + if( ia instanceof Inet4Address ) + tbl.rawPut(ia.getHostAddress(),true); + } + } + return tbl; + } + // files maps zip name to uri public static void zip(LuanState luan,String zipUri,LuanTable files) throws LuanException, IOException {