-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipdosec.py
More file actions
108 lines (90 loc) · 3.37 KB
/
ipdosec.py
File metadata and controls
108 lines (90 loc) · 3.37 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import socket
import logging
import sys
WHOIS_SERVERS = {
"com": "whois.verisign-grs.com",
"net": "whois.verisign-grs.com",
"org": "whois.pir.org",
"info": "whois.afilias.net",
"tr": "whois.nic.tr",
"co.uk": "whois.nic.uk",
"de": "whois.denic.de",
"fr": "whois.nic.fr",
"it": "whois.nic.it",
"jp": "whois.jprs.jp",
"ru": "whois.tcinet.ru",
"eu": "whois.eu",
"asia": "whois.nic.asia",
"biz": "whois.biz",
"ca": "whois.cira.ca",
"cz": "whois.nic.cz",
"pl": "whois.dns.pl",
"ip": "whois.arin.net",
"pro": "whois.registry.pro",
}
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler("whois_log.log"),
logging.StreamHandler()
]
)
def get_whois_server(domain_or_ip):
if domain_or_ip.replace('.', '').isdigit():
logging.info("sorgu bir ip adresi olduğu için varsayılan ip whois sunucusu seçildi.")
return WHOIS_SERVERS.get("ip")
domain_parts = domain_or_ip.split('.')
if len(domain_parts) > 1:
two_part_tld = f"{domain_parts[-2]}.{domain_parts[-1]}"
if two_part_tld in WHOIS_SERVERS:
return WHOIS_SERVERS.get(two_part_tld)
single_part_tld = domain_parts[-1]
return WHOIS_SERVERS.get(single_part_tld)
def whois_query(server, query_string):
port = 43
try:
logging.info(f"'{server}:{port}' adresine bağlanılıyor.")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((server, port))
s.send(f"{query_string}\r\n".encode())
response = b""
while True:
data = s.recv(1024)
if not data:
break
response += data
logging.info(f"whois sunucusundan yanıt alındı.")
return response.decode("utf-8", errors="ignore")
except Exception as e:
logging.error(f"sorgu sırasında bir hata oluştu: {e}")
return None
def get_whois_info(domain_or_ip):
query_target = domain_or_ip.replace("www.", "").replace("http://", "").replace("https://", "")
server = get_whois_server(query_target)
if not server:
logging.error(f"'{query_target}' için uygun whois sunucusu bulunamadı.")
return f"hata: desteklenmeyen alan adı veya ip adresi."
logging.info(f"'{query_target}' için whois sorgusu '{server}' üzerinden başlatılıyor.")
response = whois_query(server, query_target)
if not response:
return "sorgu başarısız oldu veya sunucuya erişilemedi."
lines = response.splitlines()
for line in lines:
if line.lower().startswith(("whois server:", "referralserver:")):
new_server = line.split(":", 1)[1].strip()
if new_server and new_server != server:
logging.info(f"yönlendirme sunucusu bulundu: '{new_server}'. yeni sorgu başlatılıyor.")
response = whois_query(new_server, query_target)
break
return response
def main():
if len(sys.argv) < 2:
print(f"Kullanım: python {sys.argv[0]} <alan_adi_veya_ip>")
sys.exit(1)
domain_or_ip = sys.argv[1]
whois_result = get_whois_info(domain_or_ip)
print(f"\n--- {domain_or_ip} için whois bilgisi ---\n")
print(whois_result)
if __name__ == "__main__":
main()