java:得到本机或网站的IP和计算机名称
来源:互联网 发布:网络配置实例 编辑:程序博客网 时间:2024/05/14 04:10
package com.happy.host;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Iterator;
public class GetIp {
public static void main(String[] args) {
try {
InetAddress addr = InetAddress.getLocalHost();
// Get IP Address
byte[] ipAddr = addr.getAddress();
String ipAddrStr = "";
for (int i=0; i<ipAddr.length; i++) {
if (i > 0) {
ipAddrStr += ".";
}
ipAddrStr += ipAddr[i]&0xFF;
}
// Get hostname
String hostname = addr.getHostName();
System.out.println(ipAddrStr+hostname);
} catch (UnknownHostException e) {
}
try {
InetAddress addr = InetAddress.getByName("javaalmanac.com");
byte[] ipAddr = addr.getAddress();
// Convert to dot representation
String ipAddrStr = "";
for (int i=0; i<ipAddr.length; i++) {
if (i > 0) {
ipAddrStr += ".";
}
ipAddrStr += ipAddr[i]&0xFF;
}
System.out.println(ipAddrStr);
} catch (UnknownHostException e) {
}
try {
// Get hostname by textual representation of IP address
InetAddress addr = InetAddress.getByName("127.0.0.1");
// Get hostname by a byte array containing the IP address
byte[] ipAddr = new byte[]{127, 0, 0, 1};
addr = InetAddress.getByAddress(ipAddr);
// Get the host name
String hostname = addr.getHostName();
// Get canonical host name
String hostnameCanonical = addr.getCanonicalHostName();
System.out.println(hostname+hostnameCanonical);
} catch (UnknownHostException e) {
}
}
}
- java:得到本机或网站的IP和计算机名称
- PB得到本机的名称和IP地址MAC地址
- PB得到本机的名称和IP地址MAC地址
- PB得到本机的名称和IP地址MAC地址
- 怎样获得本机的Ip地址和计算机的名称
- Java获取本机名称和IP地址
- 得到本机的Oracle服务器名称
- 用java的程序得到本机的ip地址
- 用java得到本机所有的ip地址
- java:得到本机IP的MAC地址
- 获取多网卡IP地址(D7~XE5)和本机计算机名称
- MFC 得到本机IP和设置本机的IP
- 获得本机IP和名称
- 获得本机外部IP和名称
- 获得本机IP和名称
- 获得本机的计算机名称
- 获取计算机的名称和IP地址
- 得到本机IP
- 面相学在HR管理中的应用
- android编写简单的Webview
- java:批量读取文件并重命名文件
- POJ 2662 A Walk Through The Forest
- WebView初探
- java:得到本机或网站的IP和计算机名称
- 2010年05月《安全天下事之缅怀中的反思》
- AnimateWindow 来美化你的对话框(淡入淡出,自动上升下降)
- 详解CSS外部引用之link与@import的区别
- 客户端检测到有潜在危险错误
- 生活必备:即时客信用卡优惠助手正式上线
- java:得到本机IP的MAC地址
- Android Sensor 适配层的书写--主要是对函数的介绍
- 委托方法好像不可以调用其它dll中的方法