modified: README.md

new file:   client/dnssender.py
	new file:   client/main.py
	new file:   database/dns.db
	new file:   database/initdb.py
	new file:   server/main.py
	new file:   server/xiaomiandns.py
This commit is contained in:
2023-03-19 10:13:45 +08:00
parent c304e2e994
commit 8131595d02
7 changed files with 298 additions and 1 deletions

22
client/dnssender.py Normal file
View File

@@ -0,0 +1,22 @@
import dns.resolver
def resolver(domain):
# 构造 DNS 查询请求
qtype = 'A'
# 发送 DNS 查询请求
resolver = dns.resolver.Resolver()
resolver.nameservers = ["127.0.0.1"]
try:
ip = resolver.resolve(domain, qtype)[0]
return ip
except dns.resolver.NXDOMAIN:
print("can't find IP")
if __name__ = "__main__":
domain = 'mamahaha.work'
ip = resolver(domain)
print(ip)

51
client/main.py Normal file
View File

@@ -0,0 +1,51 @@
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives import serialization, hashes
import random
# 生产随机域名
def generate_domain():
domain = random.getrandbits(64)
domain = hex(domain)[2:]
return domain + ".xiaomian"
# Generate a new RSA key pair
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048
)
public_key = private_key.public_key()
# Convert the public key to bytes
public_key_bytes = public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
)
# Encrypt a message using the public key
message = b"Hello World"
encrypted_message = public_key.encrypt(
message,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
# Decrypt the message using the private key
decrypted_message = private_key.decrypt(
encrypted_message,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
print(decrypted_message)
if __name__ == '__main__':
print("Welcome to my xiaomiao tor network")
domain = generate_domain()
print(domain)