beanshell : InetAddressTest.bsh
source("/sdcard/com.googlecode.bshforandroid/extras/bsh/android.bsh");
a = Android();
urlName = a.call("dialogGetInput","Inet Address Test","Input URL:").get("result");
print(urlName);
try {
if (urlName != null){
String host = urlName;
InetAddress[] addresses = InetAddress.getAllByName(host);
for (InetAddress a : addresses)
print(a);
}
else {
InetAddress localHostAddress = InetAddress.getLocalHost();
print(localHostAddress);
}
} catch (Exception e){
print(e);
}
参考: Core Java 2 Volume II ( 7th Edition) v2ch3
本文介绍了一个使用Bash脚本从用户输入获取URL并解析其主机名以获取相应IP地址的示例。该脚本同时展示了如何使用Java API(如`InetAddress`)来获取本地主机的IP地址。
903

被折叠的 条评论
为什么被折叠?



