2 package org
.de
.metux
.util
;
4 import java
.net
.InetAddress
;
5 import java
.net
.UnknownHostException
;
7 import org
.xbill
.DNS
.Lookup
;
8 import org
.xbill
.DNS
.SimpleResolver
;
9 import org
.xbill
.DNS
.Record
;
10 import org
.xbill
.DNS
.ARecord
;
11 import org
.xbill
.DNS
.Type
;
15 static public InetAddress
getIP(String hostname
, String server
)
19 Lookup l
= new Lookup(hostname
,Type
.A
);
21 l
.setResolver(new SimpleResolver(server
));
24 if (l
.getResult()==Lookup
.SUCCESSFUL
)
26 Record res
[] = l
.getAnswers();
27 for (int x
=0; x
<res
.length
; x
++)
29 ARecord arec
= (ARecord
)res
[x
];
30 return arec
.getAddress();
38 System
.err
.println("getIP() error: "+e
);
45 static public InetAddress
IPtoInetAddress(String ip
)
49 InetAddress addr
= InetAddress
.getByName(ip
);
54 System
.err
.println("EX: "+ex
);
59 static public InetAddress
getInterfaceAddress(String ifname
)
64 String res
= e
.run_catch("/sbin/ifconfig "+ifname
+" | grep \"inet addr\"");
68 int pos_addr
= res
.indexOf("inet addr:");
69 int pos_mask
= res
.indexOf(" ",pos_addr
+11);
71 String text_addr
= res
.substring(pos_addr
+10,pos_mask
).trim();
73 return IPtoInetAddress(text_addr
);