-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSClient.java
More file actions
25 lines (24 loc) · 1.02 KB
/
DNSClient.java
File metadata and controls
25 lines (24 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.*;
import java.net.*;
import java.io.*;
public class DNSClient {
public static void main(String[] args) throws Exception{
int s_port= 9080, c_port= 9090;
DatagramSocket client= new DatagramSocket(c_port);
byte[] sendBuffer= new byte[1024];
byte[] receiveBuffer= new byte[1024];
InetAddress ia= InetAddress.getLocalHost();
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
DatagramPacket packet= new DatagramPacket(receiveBuffer, receiveBuffer.length);
while(true){
System.out.println("Enter the IP address: ");
String ip= br.readLine();
sendBuffer= ip.getBytes();
client.send(new DatagramPacket(sendBuffer, ip.length(), ia, s_port));
client.receive(packet);
String msg= new String(packet.getData(), 0, packet.getLength());
System.out.println("The corresponding URL is: "+ msg);
}
//client.close();
}
}