Commit b430fcba authored by Mr Phong's avatar Mr Phong

change to json

parent 7df34c45
142.250.199.70
142.250.204.134
142.250.66.38
142.251.220.102
142.251.220.38
142.251.220.6
142.251.220.70
172.217.24.230
172.217.24.70
172.217.25.6
172.217.27.38
172.217.27.6
172.217.31.6
216.58.200.230
216.58.203.70
......@@ -28,11 +28,11 @@ Chứa source code của tool và các thông số cấu hình :
- count : Số lượng lần scan, mỗi lần scan sẽ ra 1 IP (mới hoặc cũ).
- domain : Tên domain cần scan.
- filename : Tên file chứa kết quả, mặc định là known_ips.txt. Không cần thiết phải sửa tên file này nếu không có nhu cầu đặc biệt.
- filename : Tên file chứa kết quả, mặc định là known_ips.json. Không cần thiết phải sửa tên file này nếu không có nhu cầu đặc biệt.
### 2. File known_ips.txt
### 2. File known_ips.json
Chứa danh sách ip đã scan được, lưu ý giữ nguyên nội dung file cho các lần chạy sau để tool chỉ add những ip mới (chưa có trong file)
Chứa danh sách ip đã scan được, lưu ý giữ nguyên nội dung file cho các lần chạy sau để tool chỉ add những ip mới (chưa có trong file). Nếu đổi domain để scan lại từ đầu thì chỉnh nội dung file thành danh sách rỗng []
## III. Cài đặt và chạy ứng dụng
......
......@@ -3,42 +3,40 @@ import json
def append_known_ip(filename, ip: str):
f = open(filename, "a")
f.writelines([ip, "\n"])
f.close()
known_ips = read_known_ips(filename)
known_ips.append(ip)
known_ips.sort()
with open(filename, mode="w", encoding='utf_8') as f:
json_formatted_str = json.dumps(known_ips, indent=4)
f.write(json_formatted_str)
def read_known_ips(filename):
f = open(filename, "a+")
f.close() # tạo file nếu chưa tồn tại
f = open(filename, "r")
known_ips = [line.rstrip() for line in f.readlines()]
f.close()
with open(filename, encoding='utf_8') as f:
known_ips = json.load(f)
return known_ips
def sort_result(filename):
known_ips = read_known_ips(filename)
known_ips.sort()
f = open(filename, "w")
for ip in known_ips:
f.writelines([ip, "\n"])
f.close()
def scan_ips(filename, dns_server, count, domain):
print("scan ip for domain "+domain + " with dns_server " + dns_server + " loop "+str(count) + " times !")
known_ips = read_known_ips(filename)
print("init known ips")
print(json.dumps(known_ips, indent=4))
headers = {'accept': 'application/dns-json'}
url = "https://dns.google/resolve?name="+domain
if(dns_server=="cloudflare"):
url = "https://1.1.1.1/dns-query?name="+domain
filename = "known_ips.txt"
known_ips = read_known_ips(filename)
count = 100
domain = "ad.doubleclick.net"
while count>0:
while count>0:
try:
if(count%100 == 0):
print("call next 100 request from backward count="+str(count))
headers = {'accept': 'application/dns-json'}
r = requests.get("https://1.1.1.1/dns-query?name="+domain, headers=headers)
r = requests.get(url, headers=headers)
data = json.loads(r.text)
ip = data['Answer'][0]['data']
ip = data['Answer'][0]['data'].strip()
if ip not in known_ips:
print('found new ip '+ip)
known_ips.append(ip)
......@@ -49,6 +47,17 @@ while count>0:
count=count-1
# sắp xếp lại ip theo thứ tự để dễ theo dõi
sort_result(filename)
filename = "known_ips.json"
dns_servers = ["google", "cloudflare"]
count = 100
domain = "ad.doubleclick.net"
for dns_server in dns_servers:
scan_ips(filename, dns_server, count, domain)
[
"142.250.199.70",
"142.250.204.134",
"142.250.204.38",
"142.250.204.70",
"142.250.66.38",
"142.251.220.102",
"142.251.220.38",
"142.251.220.6",
"142.251.220.70",
"172.217.24.102",
"172.217.24.230",
"172.217.24.70",
"172.217.25.6",
"172.217.27.38",
"172.217.27.6",
"172.217.31.6",
"216.58.200.230",
"216.58.203.70"
]
\ No newline at end of file
142.250.199.70
142.250.66.38
142.250.204.134
142.250.204.38
142.251.220.38
142.251.220.6
142.251.220.70
142.251.220.102
172.217.24.230
172.217.24.70
172.217.25.6
172.217.27.38
172.217.27.6
172.217.31.6
216.58.200.230
216.58.203.70
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment