简体   繁体   English

如何在ubuntu中使用计算机的IP名称来了解计算机的IP地址

[英]how to know ip address of a computer by using its pc name in ubuntu

I am currently working on a chat application. 我目前正在处理聊天应用程序。 For connecting client to server i have to enter the IP address of server manually as we are using LAN and every time server system connected it's ip gets changed. 为了将客户端连接到服务器,我必须手动输入服务器的IP地址,因为我们使用的是LAN,每次连接的服务器系统的IP都会更改。 So is there a way to find the ip address of a specific computer by just using its pc name. 因此,有一种方法可以通过仅使用其PC名称来查找特定计算机的IP地址。 I am currently using Java for implementation. 我目前正在使用Java进行实施。

InetAddress host = InetAddress.getByName("www.java2novice.com");
System.out.println(host.getHostAddress());

This link should be help you. 此链接应该可以为您提供帮助。 http://www.java2novice.com/java_networking/ip_by_host_name/ http://www.java2novice.com/java_networking/ip_by_host_name/

InetAddress ip = InetAddress.getByName("Host_Name"); // just write the host name of server machine
    System.out.println(ip.getHostAddress());

I think that will help you. 我认为这会对您有所帮助。

如果要获取Ubuntu PC的唯一IP地址,请键入:

$ hostname -I

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM