用java来写一份发起dns查询的代码
时间: 2023-05-22 16:05:34 浏览: 92
当然,我可以帮您写一份Java代码来发起DNS查询。您可以使用Java中的InetAddress类来发起DNS查询。以下是Java代码示例,您可以通过将域名替换为您想要查询的域名并运行此代码来进行发起DNS查询。
```java
import java.net.InetAddress;
import java.net.UnknownHostException;
public class DNSQuery {
public static void main(String[] args) {
try {
InetAddress address = InetAddress.getByName("www.example.com");
System.out.println("IP address: " + address.getHostAddress());
} catch (UnknownHostException e) {
System.out.println("Unable to find IP address for specified hostname");
}
}
}
```
希望这可以帮助您!
阅读全文