如何从Java中的域名获取IP地址? [英] How to get the IP address from the Domain Name in Java?

查看:576
本文介绍了如何从Java中的域名获取IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个需要IP地址的应用程序。我有一个域名,我想知道如何从中获取IP地址。例如,www.girionjava.com。如何通过Java编程获取本网站的IP地址?谢谢。

I am writing an application where I need the IP address. I have a domain name and I would like to know how to get the IP address from it. For example, "www.girionjava.com". How could I get the IP address of this website by programming in Java? Thanks.

推荐答案

InetAddress giriAddress = java.net.InetAddress.getByName("www.girionjava.com");

然后,如果你想把IP作为字符串

Then, if you want the IP as a String

String address = giriAddress.getHostAddress();

这篇关于如何从Java中的域名获取IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆