Mercurial Hosting > luan
changeset 1444:b765f146f4dc
add dns_lookup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 05 Feb 2020 08:16:15 -0700 |
parents | 42c07ecb0ddc |
children | f6075d7a36f2 |
files | src/luan/modules/Io.luan src/luan/modules/IoLuan.java |
diffstat | 2 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan/modules/Io.luan Tue Jan 28 01:16:31 2020 -0700 +++ b/src/luan/modules/Io.luan Wed Feb 05 08:16:15 2020 -0700 @@ -6,6 +6,7 @@ local Io = {} +Io.dns_lookup = IoLuan.dns_lookup Io.ip = IoLuan.ip Io.my_ips = IoLuan.my_ips Io.read_console_line = IoLuan.read_console_line
--- a/src/luan/modules/IoLuan.java Tue Jan 28 01:16:31 2020 -0700 +++ b/src/luan/modules/IoLuan.java Wed Feb 05 08:16:15 2020 -0700 @@ -28,6 +28,10 @@ import java.nio.file.Files; import java.util.Enumeration; import java.util.Map; +import javax.naming.NamingException; +import javax.naming.NameNotFoundException; +import javax.naming.directory.Attribute; +import javax.naming.directory.InitialDirContext; import luan.Luan; import luan.LuanTable; import luan.LuanFunction; @@ -673,6 +677,27 @@ return tbl; } + public static LuanTable dns_lookup(Luan luan,String domain,String type) + throws NamingException + { + LuanTable tbl = new LuanTable(luan); + InitialDirContext idc = new InitialDirContext(); + Attribute attribute; + try { + attribute = idc.getAttributes("dns:/" + domain, new String[] {type}).get(type); + } catch(NameNotFoundException e) { + return tbl; + } + if( attribute==null ) + return tbl; + final int n = attribute.size(); + for( int i=0; i<n; i++ ) { + Object obj = attribute.get(i); + tbl.rawInsert(i+1,obj); + } + return tbl; + } + private static void check(Luan luan,String name) throws LuanException { Luan.checkSecurity(luan,"uri",name);