总结:主机名,ip地址是可以实现的,关键是要掌握

package com.aa;

import java.io.IOException;
import java.net.*;

public class InetAddressTest {
	public static void main(String[] args) throws IOException {

		// 从来。
		InetAddress ia;
		ia = InetAddress.getLocalHost();// 获得本地主机的InetAddresss对象
		// 输出本地主机Ip地址
		System.out.println("本地主机IP地址:" + ia.getHostAddress());
		// 输出本地主机名
		System.out.println("本地主机名:" + ia.getHostName());
		// 输出本地主机ip地址
		System.out.println("本地主机Ip地址:" + ia.getHostAddress());
		// 获得百度网主机的InetAdderss 对象
		ia = InetAddress.getByName("www.baidu.com");// 获得主机名指定的InetAddress对象
		// 输出百度网主机IP地址
		System.out.println("百度网主机ip:" + ia.getHostAddress());
		// 输出百度网主机名
		System.out.println("百度网主机名:" + ia.getHostName());

	}

	private static InetAddress InetAddress(String string) {
		// TODO Auto-generated method stub
		return null;
	}
}




本地主机IP地址:27.18.219.15
本地主机名:2012-0101-0949
本地主机Ip地址:27.18.219.15
百度网主机ip:115.239.210.27
百度网主机名:www.baidu.com

  

相关文章:

  • 2022-03-03
  • 2021-08-04
  • 2022-12-23
  • 2021-08-12
  • 2021-06-06
  • 2021-09-02
  • 2021-11-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2021-06-07
相关资源
相似解决方案