-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDNSServer.java
29 lines (29 loc) · 1005 Bytes
/
DNSServer.java
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
26
27
28
29
import java.io.*;
import java.net.*;
public class DNSServer
{
public static DatagramSocket ds;
public static byte buffer[]=new byte[1024];
public static int clientport=789, serverport=790;
public static void main(String args[]) throws Exception
{
System.out.println("\n\n\tDNS Server using UDP\n");
ds=new DatagramSocket(clientport);
System.out.println("\tPress Ctrl+C to quit the program\n");
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
InetAddress ia=InetAddress.getLocalHost();
while(true)
{
DatagramPacket p=new DatagramPacket(buffer, buffer.length);
ds.receive(p);
String psx=new String(p.getData(), 0, p.getLength());
System.out.println("Client: "+psx);
InetAddress ib=InetAddress.getByName(psx);
System.out.println("Server Output: "+ib);
String str=dis.readLine();
if(str.equals("end")) break;
buffer=str.getBytes();
ds.send(new DatagramPacket(buffer, str.length(), ia, serverport));
}
}
}