-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDnsserver.java
77 lines (68 loc) · 1.85 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package app;
import java.net.*;
import java.io.*;
public class Dnsserver {
DataOutputStream ipaddress;
DataInputStream domainname;
static ServerSocket sock;
FileWriter datain;
FileReader domain;
BufferedWriter writedomain;
BufferedReader readip;
public final static int port = 5788;
char[] array = new char[30];
public void setnet(){
try{
System.out.println("Connecting....");
Socket client = sock.accept();
while(client.isConnected()){
domainname = new DataInputStream(client.getInputStream());
String domainadd = domainname.readUTF();
/*domain = new FileReader("Client.txt");
readip = new BufferedReader(domain);
String getdomain = readip.readLine();
for(int i=0;i<domainadd.length();i++){
for(int j=0;j<getdomain.length();j++){
//if(getdomain.charAt(j)==domainadd.charAt(i)){
if(getdomain.charAt(j)==','){
for(int k=j;k<getdomain.length();k++){
if(getdomain.charAt(j)=='<'){
for(int l=k;l<j;l++){
System.out.print(getdomain.charAt(k+1));}
}
}
}
}
// }
//}*/
switch(domainadd)
{
case "www.google.com":
ipaddress = new DataOutputStream(client.getOutputStream());
ipaddress.writeUTF("172.217.11.174");
ipaddress.flush();
System.out.print("Send ip.");
break;
case "www.facebook.com":
ipaddress = new DataOutputStream(client.getOutputStream());
ipaddress.writeUTF("32.37.14.143");
ipaddress.flush();
System.out.print("Send ip.");
break;
default :
System.out.print("Wrong Domain Name");
break;
}}}catch(IOException ex){}
}
public static void main(String args[]){
Dnsserver dns = new Dnsserver();
try {
sock = new ServerSocket(port);
System.out.println("DNS SERVER STARTED");
} catch (IOException e) {}
int random = 1;
while(random == 1){
dns.setnet();
}
}
}