From 69a9b7e24b9ac9d3f6d2237e5cf3fe939df6d675 Mon Sep 17 00:00:00 2001 From: Kasper <380587513@qq.com> Date: Mon, 5 Jul 2021 10:48:42 +0800 Subject: [PATCH 1/9] fw3e4f --- Server.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Server.java b/Server.java index f6c012e..39ebe72 100644 --- a/Server.java +++ b/Server.java @@ -45,6 +45,7 @@ public class Server { // 4.创建用于发送消息的DatagramPacket byte[] sendData = "hello,我是服务端".getBytes(); SocketAddress remoteAddress = mPacket.getSocketAddress(); + System.out.println(mPacket.getData().toString()); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, remoteAddress); // 5.向客户端发送消息 mSocket.send(sendPacket); -- Gitee From 88f1dec3c25d7b42bc6b6516775b32eb618bba35 Mon Sep 17 00:00:00 2001 From: Kasper <380587513@qq.com> Date: Mon, 5 Jul 2021 18:31:40 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E4=B8=AD=E7=BB=A7=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server.java | 100 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 25 deletions(-) diff --git a/Server.java b/Server.java index cf531d2..a8cc58a 100644 --- a/Server.java +++ b/Server.java @@ -1,7 +1,6 @@ +import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.SocketAddress; +import java.net.*; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -10,6 +9,8 @@ import java.util.HashMap; public class Server { private static DatagramSocket mSocket; private static final byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII); + public static ArrayList> mapList = new ArrayList<>(); + public static volatile boolean flag = true; public static void main(String[] args) { try { @@ -22,14 +23,21 @@ public class Server { while (true) { byte[] receiveData = new byte[1024]; DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); - mSocket.receive(receivePacket);// 在接收到信息之前,一直保持阻塞状态 - HashMap dMap = bytes2Map(receiveData); - System.out.println(dMap); - if (dMap.get("QR") == "0") { + mSocket.receive(receivePacket); // 在接收到信息之前,一直保持阻塞状态 + HashMap dMap = bytes2Map(receiveData, receivePacket.getSocketAddress()); + if ("0".equals(dMap.get("QR"))) { + System.out.println("Receive: " + dMap); HandleThread handleThread = new HandleThread(receivePacket, mSocket, dMap); + mapList.add(dMap); handleThread.setPriority(4); handleThread.start(); } + else if("1".equals(dMap.get("QR"))){ + System.out.println("Receive: " + dMap); + ResponseHandleThread responseHandleThread = new ResponseHandleThread(receivePacket, mSocket); + responseHandleThread.setPriority(4); + responseHandleThread.start(); + } } @@ -40,7 +48,7 @@ public class Server { } } - public static HashMap bytes2Map(byte[] dnsBytes) throws UnsupportedEncodingException { + public static HashMap bytes2Map(byte[] dnsBytes, SocketAddress clientAddr) throws UnsupportedEncodingException { HashMap dMap = new HashMap(); // 处理接受的头部 转成二进制字符串 @@ -49,15 +57,16 @@ public class Server { binBuf = binBuf + String.format("%8s", Integer.toBinaryString(dnsBytes[i] & 0xFF)).replace(' ', '0'); } - dMap.put("ID", binBuf.substring(0, 15)); - dMap.put("QR", binBuf.substring(15, 16)); - dMap.put("OPCODE", binBuf.substring(16, 20)); - dMap.put("AA", binBuf.substring(20, 21)); - dMap.put("TC", binBuf.substring(21, 22)); - dMap.put("RD", binBuf.substring(22, 23)); - dMap.put("RA", binBuf.substring(23, 24)); - dMap.put("Z", binBuf.substring(24, 27)); - dMap.put("RCODE", binBuf.substring(27, 31)); + dMap.put("ID", binBuf.substring(0, 16)); + dMap.put("QR", binBuf.substring(16, 17)); + dMap.put("OPCODE", binBuf.substring(17, 21)); + dMap.put("AA", binBuf.substring(21, 22)); + dMap.put("TC", binBuf.substring(22, 23)); + dMap.put("RD", binBuf.substring(23, 24)); + dMap.put("RA", binBuf.substring(24, 25)); + dMap.put("Z", binBuf.substring(25, 28)); + dMap.put("RCODE", binBuf.substring(29, 32)); + dMap.put("CLIENTADDR", clientAddr.toString()); byte[] qCountBytes = new byte[2]; qCountBytes[0] = dnsBytes[4]; @@ -77,7 +86,7 @@ public class Server { if (charDigitNum == 0) { break; } - byte[] needConvertBytes = new byte[32]; + byte[] needConvertBytes = new byte[256]; for (int i = 0; i < charDigitNum; i++) { needConvertBytes[i] = dnsBytes[qryByteIndex + i + 1]; } @@ -129,11 +138,14 @@ public class Server { public void run() { try { // 创建用于发送消息的DatagramPacket - byte[] sendData = buildRespData(); - SocketAddress remoteAddress = mPacket.getSocketAddress(); - System.out.println(mPacket.getData().toString()); - DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, remoteAddress); - // 向客户端发送消息 +// byte[] sendData = buildRespData(); +// SocketAddress remoteAddress = mPacket.getSocketAddress(); +// DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, remoteAddress); +// // 向客户端发送消息 +// mSocket.send(sendPacket); + byte[] payload = mPacket.getData(); + SocketAddress remoteAddress = new InetSocketAddress("10.3.9.44", 53); + DatagramPacket sendPacket = new DatagramPacket(payload, payload.length, remoteAddress); mSocket.send(sendPacket); } catch (Exception e) { e.printStackTrace(); @@ -199,10 +211,48 @@ public class Server { } public byte[] binString2ByteAry(String binString) { - short a = Short.parseShort(binString, 2); - ByteBuffer bytes = ByteBuffer.allocate(2).putShort(a); + int a = Integer.parseInt(binString, 2); + ByteBuffer bytes = ByteBuffer.allocate(16).putInt(a); byte[] array = bytes.array(); return array; } } + + static class ResponseHandleThread extends Thread{ + private DatagramPacket packet; + private DatagramSocket socket; + + public ResponseHandleThread(DatagramPacket packet, DatagramSocket socket){ + this.packet = packet; + this.socket = socket; + } + @Override + public synchronized void run(){ + byte[] payload = packet.getData(); + try { + System.out.println("1"); +// while(!flag){} +// flag = false; + System.out.println("2"); + HashMap rMap = bytes2Map(payload, packet.getSocketAddress()); + String tId = rMap.get("ID"); + for(HashMap map : mapList){ + if(map.get("ID").equals(tId)){ + String host = map.get("CLIENTADDR").replaceAll("/", "").split(":")[0]; + Integer port = Integer.parseInt(map.get("CLIENTADDR").replaceAll("/", "").split(":")[1]); + SocketAddress clientAddr = new InetSocketAddress(host, port); + DatagramPacket rPacket = new DatagramPacket(payload, payload.length, clientAddr); + socket.send(rPacket); + System.out.println("Send to " + host + ":" + port + " -- " + rMap); + mapList.remove(map); + } + } +// flag = true; + } catch (UnsupportedEncodingException | UnknownHostException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } } \ No newline at end of file -- Gitee From bd67f52d574ac9ec2392ede7b68cee2f914e1648 Mon Sep 17 00:00:00 2001 From: Kasper <380587513@qq.com> Date: Tue, 6 Jul 2021 22:06:52 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ClassType.java | 6 +++ QueryType.java | 19 ++++++++ RecordMapper.java | 81 ++++++++++++++++++++++++++++++++++ ResponseBuilder.java | 102 +++++++++++++++++++++++++++++++++++++++++++ Server.java | 16 ++++--- relay.txt | 4 ++ 6 files changed, 223 insertions(+), 5 deletions(-) create mode 100644 ClassType.java create mode 100644 QueryType.java create mode 100644 RecordMapper.java create mode 100644 ResponseBuilder.java create mode 100644 relay.txt diff --git a/ClassType.java b/ClassType.java new file mode 100644 index 0000000..a393636 --- /dev/null +++ b/ClassType.java @@ -0,0 +1,6 @@ +public class ClassType { + public static final int IN = 1; + public static final int CS = 2; + public static final int CH = 3; + public static final int HS = 4; +} diff --git a/QueryType.java b/QueryType.java new file mode 100644 index 0000000..561e2d7 --- /dev/null +++ b/QueryType.java @@ -0,0 +1,19 @@ +public class QueryType { + public static final int A = 1 ; + public static final int NS = 2 ; + public static final int MD = 3 ; + public static final int MF = 4 ; + public static final int CNAME = 5 ; + public static final int SOA = 6 ; + public static final int MB = 7 ; + public static final int MG = 8 ; + public static final int MR = 9 ; + public static final int NULL = 10; + public static final int WKS = 11; + public static final int PTR = 12; + public static final int HINFO = 13; + public static final int MINFO = 14; + public static final int MX = 15; + public static final int TXT = 16; +} + diff --git a/RecordMapper.java b/RecordMapper.java new file mode 100644 index 0000000..91ef1f9 --- /dev/null +++ b/RecordMapper.java @@ -0,0 +1,81 @@ +import java.io.*; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashMap; + +public class RecordMapper { + private String qname; + private String mappedIP = "x"; + private DatagramPacket inPacket; + private HashMap inMap; + public RecordMapper(DatagramPacket inPacket, HashMap inMap) throws IOException { + this.qname = getQName(inPacket); + this.inMap = inMap; + this.inPacket = inPacket; + } + + public boolean isRecorded() throws IOException { + mappedIP = getIPAddr(); + if(mappedIP.equals("x")){ + return false; + } + else { + return true; + } + } + + public void sendResponse(DatagramSocket mSocket) throws IOException { + ResponseBuilder rb = new ResponseBuilder(inMap, inPacket, mappedIP); + byte[] payload = rb.buildA(); + SocketAddress remoteAddress = inPacket.getSocketAddress(); + DatagramPacket sendPacket = new DatagramPacket(payload, payload.length, remoteAddress); + mSocket.send(sendPacket); + } + + public String getIPAddr() throws IOException { + File f = new File("relay.txt"); + BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(f))); + String line = ""; + while((line = in.readLine()) != null){ + String fname = line.split(" ")[1]; +// System.out.println(fname.hashCode() + " - " + qname.hashCode()); +// System.out.println(fname + " - " + qname); +// System.out.println(fname.equals(qname)); +// System.out.println(Arrays.toString(new String(qname.getBytes()).getBytes())); +// System.out.println(Arrays.toString(fname.getBytes())); + if(line.split(" ")[1].equals(qname)){ + System.out.println(line.split(" ")[0] + " - " + line.split(" ")[1]); + return line.split(" ")[0]; + } + } + return "x"; + } + + public String getQName(DatagramPacket packet){ + byte[] data = packet.getData(); +// System.out.println(Arrays.toString(data)); + int i = 13, j = 0; + while(data[i] != 0){ + i++; + } + byte[] qnameByte = new byte[i-13]; + i = 13; + while(data[i] != 0){ + if(data[i] > 47) { + qnameByte[j] = data[i]; + j++; + } + else { + qnameByte[j] = '.'; + j++; + } + i++; + } +// System.out.println(Arrays.toString(qnameByte)); + return new String(qnameByte); + } +} diff --git a/ResponseBuilder.java b/ResponseBuilder.java new file mode 100644 index 0000000..736d2e8 --- /dev/null +++ b/ResponseBuilder.java @@ -0,0 +1,102 @@ +import java.net.DatagramPacket; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashMap; + +public class ResponseBuilder { + private HashMap inMap; + private DatagramPacket inPacket; + private String srcIP; + public ResponseBuilder(HashMap inMap, DatagramPacket inPacket, String srcIP){ + this.inMap = inMap; + this.inPacket = inPacket; + this.srcIP = srcIP; + } + + public byte[] buildA(){ + System.out.println(srcIP); + int flags; + byte[] data = new byte[1024]; + System.out.println("in packet: " + Arrays.toString(inPacket.getData())); + int i = 0; + for(i = 0; i < inPacket.getData().length; i++){ + data[i] = inPacket.getData()[i]; + } + for(i = 13; inPacket.getData()[i] != 0; i++){ + } + int length = i + 5; + if(srcIP.equals("0.0.0.0")){ + flags = 0x8183; + } + else { + flags = 0x8180; + } + data[2] = (byte) ((flags >> 8) & 0xFF); + data[3] = (byte) (flags & 0xFF); + data[7] = 0x1; + data[length] = (byte) 0xc0; + data[length+1] = (byte) 0x0c; + data[length+2] = (byte) 0x0; + data[length+3] = (byte) QueryType.A; + data[length+4] = (byte) 0x0; + data[length+5] = (byte) ClassType.IN; + data[length+6] = (byte) 0x0; + data[length+7] = (byte) 0x0; + data[length+8] = (byte) 0x0; + data[length+9] = (byte) 0xe0; + data[length+10] = (byte) 0x0; + data[length+11] = (byte) 0x4; + String[] ip = srcIP.split("[.]"); + System.out.println(Arrays.toString(ip)); + System.out.println("Response: " + Arrays.toString(data)); + data[length+12] = (byte) Integer.parseInt(ip[0]); + data[length+13] = (byte) Integer.parseInt(ip[1]); + data[length+14] = (byte) Integer.parseInt(ip[2]); + data[length+15] = (byte) Integer.parseInt(ip[3]); + return data; + } + + public static byte[] hexToByte(int hex, int byteLength){ + byte[] src = Integer.toBinaryString(hex).getBytes(StandardCharsets.UTF_8); + byte[] res = new byte[byteLength]; + for(int i = 0; i < byteLength; i++){ + if(i < byteLength - src.length){ + res[i] = 0; + } + else { + src[i - byteLength + src.length] -= 48; + res[i] = src[ i - byteLength + src.length]; + } + } + return res; + } + + public byte[] ipToBytes(String ip){ + byte[] res = new byte[32]; + writeBytesFromBytes(res, 0, hexToByte(Integer.parseInt(ip.split(".")[0]), 8)); + writeBytesFromBytes(res, 8, hexToByte(Integer.parseInt(ip.split(".")[1]), 8)); + writeBytesFromBytes(res, 16, hexToByte(Integer.parseInt(ip.split(".")[2]), 8)); + writeBytesFromBytes(res, 24, hexToByte(Integer.parseInt(ip.split(".")[3]), 8)); + return res; + } + + public static void writeBytesFromHex(byte[] target, int cursor, int hex){ + byte[] src = Integer.toBinaryString(hex).getBytes(StandardCharsets.UTF_8); + for(int i = 0; i < src.length; i++){ + target[i+cursor] = src[i]; + } + } + + public static void writeBytesFromBytes(byte[] target, int cursor, byte[] src){ + for(int i = 0; i < src.length; i++){ + target[i+cursor] = src[i]; + } + } + + public static void main(String[] args) { + byte[] data = ResponseBuilder.hexToByte(0xc00c, 16); + for(int i = 0; i < 16; i++){ + System.out.println(data[i]); + } + } +} diff --git a/Server.java b/Server.java index a8cc58a..0f76e81 100644 --- a/Server.java +++ b/Server.java @@ -28,7 +28,6 @@ public class Server { if ("0".equals(dMap.get("QR"))) { System.out.println("Receive: " + dMap); HandleThread handleThread = new HandleThread(receivePacket, mSocket, dMap); - mapList.add(dMap); handleThread.setPriority(4); handleThread.start(); } @@ -143,10 +142,17 @@ public class Server { // DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, remoteAddress); // // 向客户端发送消息 // mSocket.send(sendPacket); - byte[] payload = mPacket.getData(); - SocketAddress remoteAddress = new InetSocketAddress("10.3.9.44", 53); - DatagramPacket sendPacket = new DatagramPacket(payload, payload.length, remoteAddress); - mSocket.send(sendPacket); + RecordMapper rm = new RecordMapper(mPacket, dMap); + if(rm.isRecorded()){ + rm.sendResponse(mSocket); + } + else { + mapList.add(dMap); + byte[] payload = mPacket.getData(); + SocketAddress remoteAddress = new InetSocketAddress("10.3.9.44", 53); + DatagramPacket sendPacket = new DatagramPacket(payload, payload.length, remoteAddress); + mSocket.send(sendPacket); + } } catch (Exception e) { e.printStackTrace(); } finally { diff --git a/relay.txt b/relay.txt new file mode 100644 index 0000000..4ff9770 --- /dev/null +++ b/relay.txt @@ -0,0 +1,4 @@ +10.3.8.216 www.baidu.com +0.0.0.0 www.sogou.com +0.0.0.0 www.sohu.com +39.156.66.18 www.google.com -- Gitee From 98788f7e96cf84af0f48b71ef80a44891ae0622e Mon Sep 17 00:00:00 2001 From: Kasper <380587513@qq.com> Date: Tue, 6 Jul 2021 22:44:48 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ClassType.java | 2 +- run.sh | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 run.sh diff --git a/ClassType.java b/ClassType.java index a393636..6b4e97b 100644 --- a/ClassType.java +++ b/ClassType.java @@ -3,4 +3,4 @@ public class ClassType { public static final int CS = 2; public static final int CH = 3; public static final int HS = 4; -} +} \ No newline at end of file diff --git a/run.sh b/run.sh deleted file mode 100644 index 8bbe142..0000000 --- a/run.sh +++ /dev/null @@ -1,3 +0,0 @@ - -javac Server.java -java Server \ No newline at end of file -- Gitee From f90a358a2dbe262c45f7af1982639ac2496a4a8a Mon Sep 17 00:00:00 2001 From: Kasper <380587513@qq.com> Date: Tue, 6 Jul 2021 22:45:05 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 + .idea/inspectionProfiles/Project_Default.xml | 36 ++++ .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + dns-server-java.iml | 11 + out/production/dns-server-java/.gitignore | 1 + .../dns-server-java/.idea/.gitignore | 8 + .../inspectionProfiles/Project_Default.xml | 36 ++++ out/production/dns-server-java/.idea/misc.xml | 6 + .../dns-server-java/.idea/modules.xml | 8 + out/production/dns-server-java/.idea/vcs.xml | 6 + out/production/dns-server-java/LICENSE | 201 ++++++++++++++++++ out/production/dns-server-java/README.md | 37 ++++ .../dns-server-java/dns-server-java.iml | 11 + out/production/dns-server-java/relay.txt | 3 + out/production/dns-server-java/run.sh | 3 + 17 files changed, 395 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 dns-server-java.iml create mode 100644 out/production/dns-server-java/.gitignore create mode 100644 out/production/dns-server-java/.idea/.gitignore create mode 100644 out/production/dns-server-java/.idea/inspectionProfiles/Project_Default.xml create mode 100644 out/production/dns-server-java/.idea/misc.xml create mode 100644 out/production/dns-server-java/.idea/modules.xml create mode 100644 out/production/dns-server-java/.idea/vcs.xml create mode 100644 out/production/dns-server-java/LICENSE create mode 100644 out/production/dns-server-java/README.md create mode 100644 out/production/dns-server-java/dns-server-java.iml create mode 100644 out/production/dns-server-java/relay.txt create mode 100644 out/production/dns-server-java/run.sh diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..1c4673b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../../:\Users\Kasper Sergeievic\Documents\dns-server-java\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..40674af --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c90df45 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/dns-server-java.iml b/dns-server-java.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/dns-server-java.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/dns-server-java/.gitignore b/out/production/dns-server-java/.gitignore new file mode 100644 index 0000000..6b468b6 --- /dev/null +++ b/out/production/dns-server-java/.gitignore @@ -0,0 +1 @@ +*.class diff --git a/out/production/dns-server-java/.idea/.gitignore b/out/production/dns-server-java/.idea/.gitignore new file mode 100644 index 0000000..1c4673b --- /dev/null +++ b/out/production/dns-server-java/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/../../../../../../:\Users\Kasper Sergeievic\Documents\dns-server-java\.idea/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/out/production/dns-server-java/.idea/inspectionProfiles/Project_Default.xml b/out/production/dns-server-java/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/out/production/dns-server-java/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/out/production/dns-server-java/.idea/misc.xml b/out/production/dns-server-java/.idea/misc.xml new file mode 100644 index 0000000..40674af --- /dev/null +++ b/out/production/dns-server-java/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/dns-server-java/.idea/modules.xml b/out/production/dns-server-java/.idea/modules.xml new file mode 100644 index 0000000..c90df45 --- /dev/null +++ b/out/production/dns-server-java/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/dns-server-java/.idea/vcs.xml b/out/production/dns-server-java/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/out/production/dns-server-java/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/dns-server-java/LICENSE b/out/production/dns-server-java/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/out/production/dns-server-java/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/out/production/dns-server-java/README.md b/out/production/dns-server-java/README.md new file mode 100644 index 0000000..9b710db --- /dev/null +++ b/out/production/dns-server-java/README.md @@ -0,0 +1,37 @@ +# dns-server-java + +#### 介绍 +java实现的dns server + +#### 软件架构 +软件架构说明 + + +#### 安装教程 + +1. xxxx +2. xxxx +3. xxxx + +#### 使用说明 + +1. xxxx +2. xxxx +3. xxxx + +#### 参与贡献 + +1. Fork 本仓库 +2. 新建 Feat_xxx 分支 +3. 提交代码 +4. 新建 Pull Request + + +#### 特技 + +1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md +2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) +3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 +4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 +5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) +6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/out/production/dns-server-java/dns-server-java.iml b/out/production/dns-server-java/dns-server-java.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/out/production/dns-server-java/dns-server-java.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/dns-server-java/relay.txt b/out/production/dns-server-java/relay.txt new file mode 100644 index 0000000..8760ec6 --- /dev/null +++ b/out/production/dns-server-java/relay.txt @@ -0,0 +1,3 @@ +10.122.237.127 www.baidu.com +0.0.0.0 google.com +39.156.66.18 baidu diff --git a/out/production/dns-server-java/run.sh b/out/production/dns-server-java/run.sh new file mode 100644 index 0000000..8bbe142 --- /dev/null +++ b/out/production/dns-server-java/run.sh @@ -0,0 +1,3 @@ + +javac Server.java +java Server \ No newline at end of file -- Gitee From cce7744ec0db6bbf6a4edb77ace518d3dacf55b5 Mon Sep 17 00:00:00 2001 From: Kasper <380587513@qq.com> Date: Tue, 6 Jul 2021 23:03:11 +0800 Subject: [PATCH 6/9] gitignore --- .gitignore | 1 + out/production/dns-server-java/.gitignore | 1 - .../dns-server-java/.idea/.gitignore | 8 - .../inspectionProfiles/Project_Default.xml | 36 ---- out/production/dns-server-java/.idea/misc.xml | 6 - .../dns-server-java/.idea/modules.xml | 8 - out/production/dns-server-java/.idea/vcs.xml | 6 - out/production/dns-server-java/LICENSE | 201 ------------------ out/production/dns-server-java/README.md | 37 ---- .../dns-server-java/dns-server-java.iml | 11 - out/production/dns-server-java/relay.txt | 3 - out/production/dns-server-java/run.sh | 3 - 12 files changed, 1 insertion(+), 320 deletions(-) delete mode 100644 out/production/dns-server-java/.gitignore delete mode 100644 out/production/dns-server-java/.idea/.gitignore delete mode 100644 out/production/dns-server-java/.idea/inspectionProfiles/Project_Default.xml delete mode 100644 out/production/dns-server-java/.idea/misc.xml delete mode 100644 out/production/dns-server-java/.idea/modules.xml delete mode 100644 out/production/dns-server-java/.idea/vcs.xml delete mode 100644 out/production/dns-server-java/LICENSE delete mode 100644 out/production/dns-server-java/README.md delete mode 100644 out/production/dns-server-java/dns-server-java.iml delete mode 100644 out/production/dns-server-java/relay.txt delete mode 100644 out/production/dns-server-java/run.sh diff --git a/.gitignore b/.gitignore index 6b468b6..b3fa749 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.class +.idea/* \ No newline at end of file diff --git a/out/production/dns-server-java/.gitignore b/out/production/dns-server-java/.gitignore deleted file mode 100644 index 6b468b6..0000000 --- a/out/production/dns-server-java/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.class diff --git a/out/production/dns-server-java/.idea/.gitignore b/out/production/dns-server-java/.idea/.gitignore deleted file mode 100644 index 1c4673b..0000000 --- a/out/production/dns-server-java/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/../../../../../../:\Users\Kasper Sergeievic\Documents\dns-server-java\.idea/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/out/production/dns-server-java/.idea/inspectionProfiles/Project_Default.xml b/out/production/dns-server-java/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 6560a98..0000000 --- a/out/production/dns-server-java/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - \ No newline at end of file diff --git a/out/production/dns-server-java/.idea/misc.xml b/out/production/dns-server-java/.idea/misc.xml deleted file mode 100644 index 40674af..0000000 --- a/out/production/dns-server-java/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/out/production/dns-server-java/.idea/modules.xml b/out/production/dns-server-java/.idea/modules.xml deleted file mode 100644 index c90df45..0000000 --- a/out/production/dns-server-java/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/out/production/dns-server-java/.idea/vcs.xml b/out/production/dns-server-java/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/out/production/dns-server-java/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/out/production/dns-server-java/LICENSE b/out/production/dns-server-java/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/out/production/dns-server-java/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/out/production/dns-server-java/README.md b/out/production/dns-server-java/README.md deleted file mode 100644 index 9b710db..0000000 --- a/out/production/dns-server-java/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# dns-server-java - -#### 介绍 -java实现的dns server - -#### 软件架构 -软件架构说明 - - -#### 安装教程 - -1. xxxx -2. xxxx -3. xxxx - -#### 使用说明 - -1. xxxx -2. xxxx -3. xxxx - -#### 参与贡献 - -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request - - -#### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/out/production/dns-server-java/dns-server-java.iml b/out/production/dns-server-java/dns-server-java.iml deleted file mode 100644 index b107a2d..0000000 --- a/out/production/dns-server-java/dns-server-java.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/out/production/dns-server-java/relay.txt b/out/production/dns-server-java/relay.txt deleted file mode 100644 index 8760ec6..0000000 --- a/out/production/dns-server-java/relay.txt +++ /dev/null @@ -1,3 +0,0 @@ -10.122.237.127 www.baidu.com -0.0.0.0 google.com -39.156.66.18 baidu diff --git a/out/production/dns-server-java/run.sh b/out/production/dns-server-java/run.sh deleted file mode 100644 index 8bbe142..0000000 --- a/out/production/dns-server-java/run.sh +++ /dev/null @@ -1,3 +0,0 @@ - -javac Server.java -java Server \ No newline at end of file -- Gitee From 6c02a74787e3af8605de7fa0f9ea251eb9a87ce8 Mon Sep 17 00:00:00 2001 From: Kasper <380587513@qq.com> Date: Tue, 6 Jul 2021 23:04:47 +0800 Subject: [PATCH 7/9] gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b3fa749..ca7a69a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *.class -.idea/* \ No newline at end of file +.idea/ \ No newline at end of file -- Gitee From 335211ceea06bada2c99fc55140d8b6409ef61b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B3=E7=AC=91=E5=90=8D?= <380587513@qq.com> Date: Tue, 6 Jul 2021 15:05:05 +0000 Subject: [PATCH 8/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20.ide?= =?UTF-8?q?a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 ----- .idea/inspectionProfiles/Project_Default.xml | 36 -------------------- .idea/misc.xml | 6 ---- .idea/modules.xml | 8 ----- .idea/vcs.xml | 6 ---- 5 files changed, 64 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 1c4673b..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/../../../../../../:\Users\Kasper Sergeievic\Documents\dns-server-java\.idea/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 6560a98..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 40674af..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index c90df45..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file -- Gitee From 03802c944d51fe055a1396b526da063ed3770f53 Mon Sep 17 00:00:00 2001 From: Kasper <380587513@qq.com> Date: Wed, 7 Jul 2021 00:38:55 +0800 Subject: [PATCH 9/9] ok --- Server.java | 176 ++++++++++++++-------- out/production/dns-server-java/.gitignore | 2 + 2 files changed, 112 insertions(+), 66 deletions(-) create mode 100644 out/production/dns-server-java/.gitignore diff --git a/Server.java b/Server.java index 0f76e81..0e10c86 100644 --- a/Server.java +++ b/Server.java @@ -1,37 +1,37 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.*; -import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; +import java.util.concurrent.CopyOnWriteArrayList; public class Server { private static DatagramSocket mSocket; private static final byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII); - public static ArrayList> mapList = new ArrayList<>(); - public static volatile boolean flag = true; + public static CopyOnWriteArrayList> mapList = new CopyOnWriteArrayList<>(); public static void main(String[] args) { try { - // 1.初始化DatagramSocket,指定端口号 + // new DatagramSocket mSocket = new DatagramSocket(53); - // 2.创建用于接收消息的DatagramPacket,指定接收数据大小 - // 3.接收客户端消息 - System.out.println("***************服务器开始监听消息***************"); + // accept client datagram + System.out.println("***************start listening***************"); while (true) { byte[] receiveData = new byte[1024]; DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); - mSocket.receive(receivePacket); // 在接收到信息之前,一直保持阻塞状态 - HashMap dMap = bytes2Map(receiveData, receivePacket.getSocketAddress()); - if ("0".equals(dMap.get("QR"))) { - System.out.println("Receive: " + dMap); + mSocket.receive(receivePacket);// block until receive packet + HashMap dMap = bytes2Map(receiveData); + System.out.println(dMap); + if (dMap.get("QR").equals("0")) { + dMap.put("CLIADDR", receivePacket.getSocketAddress().toString()); + mapList.add(dMap); + System.out.println(dMap); HandleThread handleThread = new HandleThread(receivePacket, mSocket, dMap); handleThread.setPriority(4); handleThread.start(); - } - else if("1".equals(dMap.get("QR"))){ + } else if (dMap.get("QR").equals("1")) { System.out.println("Receive: " + dMap); ResponseHandleThread responseHandleThread = new ResponseHandleThread(receivePacket, mSocket); responseHandleThread.setPriority(4); @@ -43,14 +43,14 @@ public class Server { } catch (Exception e) { e.printStackTrace(); } finally { - mSocket.close();// 关闭资源 + mSocket.close();// close socket } } - public static HashMap bytes2Map(byte[] dnsBytes, SocketAddress clientAddr) throws UnsupportedEncodingException { + public static HashMap bytes2Map(byte[] dnsBytes) throws UnsupportedEncodingException { HashMap dMap = new HashMap(); - // 处理接受的头部 转成二进制字符串 + // qry head to bin str String binBuf = ""; for (int i = 0; i < 4; i++) { binBuf = binBuf + String.format("%8s", Integer.toBinaryString(dnsBytes[i] & 0xFF)).replace(' ', '0'); @@ -64,8 +64,7 @@ public class Server { dMap.put("RD", binBuf.substring(23, 24)); dMap.put("RA", binBuf.substring(24, 25)); dMap.put("Z", binBuf.substring(25, 28)); - dMap.put("RCODE", binBuf.substring(29, 32)); - dMap.put("CLIENTADDR", clientAddr.toString()); + dMap.put("RCODE", binBuf.substring(28, 32)); byte[] qCountBytes = new byte[2]; qCountBytes[0] = dnsBytes[4]; @@ -77,7 +76,7 @@ public class Server { // for(int i=4;i<72;i++) // System.out.println(Byte.toUnsignedInt(dnsBytes[i])); - // 查询名处理 转成正常字符串 + // qname to char str String qryName = ""; int qryByteIndex = 12; while (true) { @@ -98,7 +97,7 @@ public class Server { dMap.put("QNAME", qryName); dMap.put("QNAME_ASS_INDEX", String.valueOf(qryByteIndex + 1)); - // 查询尾部处理 转成十六进制字符串 + // Tail of qry to hex str byte[] qryAss = new byte[4]; for (int i = 0; i < 4; i++) { qryAss[i] = dnsBytes[qryByteIndex + i + 1]; @@ -120,7 +119,7 @@ public class Server { return new String(hexChars, StandardCharsets.UTF_8); } - // 处理DNS请求的线程 + // thread deal with qry static class HandleThread extends Thread { private DatagramPacket mPacket; private DatagramSocket mSocket; @@ -136,22 +135,18 @@ public class Server { @Override public void run() { try { - // 创建用于发送消息的DatagramPacket -// byte[] sendData = buildRespData(); -// SocketAddress remoteAddress = mPacket.getSocketAddress(); -// DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, remoteAddress); -// // 向客户端发送消息 -// mSocket.send(sendPacket); RecordMapper rm = new RecordMapper(mPacket, dMap); if(rm.isRecorded()){ rm.sendResponse(mSocket); } else { - mapList.add(dMap); - byte[] payload = mPacket.getData(); - SocketAddress remoteAddress = new InetSocketAddress("10.3.9.44", 53); - DatagramPacket sendPacket = new DatagramPacket(payload, payload.length, remoteAddress); - mSocket.send(sendPacket); + // new DatagramPacket + byte[] sendData = buildRespData(); + if (sendData.length > 4) { + SocketAddress remoteAddress = mPacket.getSocketAddress(); + DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, remoteAddress); + mSocket.send(sendPacket); + } } } catch (Exception e) { e.printStackTrace(); @@ -159,22 +154,9 @@ public class Server { } } - public byte[] buildQryData() { - ArrayList qryDataAryLst = new ArrayList(); - - //中继查找用的 - - // 转成数组 - byte[] qryDataAry = new byte[qryDataAryLst.size()]; - for (int i = 0; i < qryDataAryLst.size(); i++) { - qryDataAry[i] = qryDataAryLst.get(i); - } - return qryDataAry; - } - public byte[] buildRespData() { ArrayList respDataAryLst = new ArrayList(); - int ansNum = 1;// 可变 + int ansNum = 0;// 可变 // 构建头部 String headBinString = ""; headBinString = dMap.get("ID") + "1" + dMap.get("OPCODE") + dMap.get("AA") + dMap.get("TC") + dMap.get("RD") @@ -196,16 +178,28 @@ public class Server { // 构建结果 // same as qry part - byte[] qryData = new byte[1024]; + byte[] qryData = mPacket.getData(); mPacket = new DatagramPacket(qryData, qryData.length); for (int i = 12; i < Integer.parseInt(dMap.get("QNAME_ASS_INDEX")) + 4; i++) { respDataAryLst.add(qryData[i]); } + Boolean matchFlag = false; // real answer part - for (int i = 0; i < ansNum; i++) { // 循环直到遍历所有结果 - // match name & qryType - // 如果本地表找不到就中继 + // while (false) { // traversal the local table + // match name & qryType + + // ansNum++; + // } + + // relay if no matching + if (matchFlag == false) { + dealWithRelay(); + respDataAryLst.clear(); + respDataAryLst.add((byte) 'F'); + respDataAryLst.add((byte) 'U'); + respDataAryLst.add((byte) 'C'); + respDataAryLst.add((byte) 'K'); } // 转成数组 @@ -216,36 +210,86 @@ public class Server { return respDataAry; } - public byte[] binString2ByteAry(String binString) { - int a = Integer.parseInt(binString, 2); - ByteBuffer bytes = ByteBuffer.allocate(16).putInt(a); - byte[] array = bytes.array(); - return array; + public void dealWithRelay() { + try { + // new DatagramPacket + byte[] sendData = buildQryData(); + DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, + InetAddress.getByName("10.3.9.45"), 53); + mSocket.send(sendPacket); + System.out.println("relayed"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + } + } + + public byte[] buildQryData() { + ArrayList qryDataAryLst = new ArrayList(); + byte[] qryData = mPacket.getData(); + + // 中继 + for (int i = 0; i < Integer.parseInt(dMap.get("QNAME_ASS_INDEX")) + 4; i++) { + qryDataAryLst.add(qryData[i]); + } + + // 转成数组 + byte[] qryDataAry = new byte[qryDataAryLst.size()]; + for (int i = 0; i < qryDataAryLst.size(); i++) { + qryDataAry[i] = qryDataAryLst.get(i); + } + return qryDataAry; + } + + public static byte[] binString2ByteAry(String binString) { + ArrayList byteAryLst = new ArrayList(); + int byteNum = binString.length() / 8; + int byteVal = 0; + int st = 1; + for (int i = 0; i < byteNum; i++) { + for (int j = 0; j < 8; j++) { + if (binString.charAt(8 * i + j) == '1') { + for (int k = 0; k < 8 - j - 1; k++) { + st = st * 2; + } + byteVal += st; + st = 1; + } + } + byteAryLst.add((byte) byteVal); + byteVal = 0; + } + byte[] byteAry = new byte[byteAryLst.size()]; + for (int i = 0; i < byteAryLst.size(); i++) { + byteAry[i] = byteAryLst.get(i); + } + return byteAry; } } - static class ResponseHandleThread extends Thread{ + static class ResponseHandleThread extends Thread { private DatagramPacket packet; private DatagramSocket socket; - public ResponseHandleThread(DatagramPacket packet, DatagramSocket socket){ + public ResponseHandleThread(DatagramPacket packet, DatagramSocket socket) { this.packet = packet; this.socket = socket; } + @Override - public synchronized void run(){ + public synchronized void run() { byte[] payload = packet.getData(); try { System.out.println("1"); -// while(!flag){} -// flag = false; + // while(!flag){} + // flag = false; System.out.println("2"); - HashMap rMap = bytes2Map(payload, packet.getSocketAddress()); + HashMap rMap = bytes2Map(payload); String tId = rMap.get("ID"); - for(HashMap map : mapList){ - if(map.get("ID").equals(tId)){ - String host = map.get("CLIENTADDR").replaceAll("/", "").split(":")[0]; - Integer port = Integer.parseInt(map.get("CLIENTADDR").replaceAll("/", "").split(":")[1]); + for (HashMap map : mapList) { + if (map.get("ID").equals(tId)) { + String host = map.get("CLIADDR").replaceAll("/", "").split(":")[0]; + Integer port = Integer.parseInt(map.get("CLIADDR").replaceAll("/", "").split(":")[1]); SocketAddress clientAddr = new InetSocketAddress(host, port); DatagramPacket rPacket = new DatagramPacket(payload, payload.length, clientAddr); socket.send(rPacket); @@ -253,7 +297,7 @@ public class Server { mapList.remove(map); } } -// flag = true; + // flag = true; } catch (UnsupportedEncodingException | UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { diff --git a/out/production/dns-server-java/.gitignore b/out/production/dns-server-java/.gitignore new file mode 100644 index 0000000..ca7a69a --- /dev/null +++ b/out/production/dns-server-java/.gitignore @@ -0,0 +1,2 @@ +*.class +.idea/ \ No newline at end of file -- Gitee