简体   繁体   中英

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. So is there a way to find the ip address of a specific computer by just using its pc name. I am currently using Java for implementation.

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/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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