| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
ecfc
10年前发布

java实现根据域名获得ip地址代码

mport java.net.InetAddress;  import java.net.UnknownHostException;    public class GetIPAddressFromHostname {        public static void main(String[] args) {            try {                InetAddress inetAddr = InetAddress.getByName("open-open.com");                byte[] addr = inetAddr.getAddress();                // Convert to dot representation              String ipAddr = "";              for (int i = 0; i < addr.length; i++) {                  if (i > 0) {                      ipAddr += ".";                  }                  ipAddr += addr[i] & 0xFF;              }                System.out.println("IP Address: " + ipAddr);            }          catch (UnknownHostException e) {              System.out.println("Host not found: " + e.getMessage());          }        }    }