-
Notifications
You must be signed in to change notification settings - Fork 0
/
others.py
79 lines (65 loc) · 2.43 KB
/
others.py
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
import re
import socket
import subprocess
import time
def run_process(process):
p = subprocess.Popen(process, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
line = p.stdout.readline()
while line != b'\x92\xe0\xa0\xe1\xe1\xa8\xe0\xae\xa2\xaa\xa0 \xa7\xa0\xa2\xa5\xe0\xe8\xa5\xad\xa0.\r\n':
line = p.stdout.readline()
yield line
def get_ip(line):
lines = line.decode('cp866').split(' ')
r = re.compile(
r"^([1][0-9][0-9].|^[2][5][0-5].|^[2][0-4][0-9].|^[1][0-9][0-9].|^[0-9][0-9].|^[0-9].)([1][0-9][0-9].|[2][5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([1][0-9][0-9].|[2][5][0-5].|[2][0-4][0-9].|[1][0-9][0-9].|[0-9][0-9].|[0-9].)([1][0-9][0-9]|[2][5][0-5]|[2][0-4][0-9]|[1][0-9][0-9]|[0-9][0-9]|[0-9])$")
lines = list(filter(r.match, lines))
if len(list(filter(r.match, lines))) != 0:
return lines[0]
else:
return 'No ip'
def make_request(ip, server):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server, 43))
if server == 'whois.arin.net':
s.send(('n + ' + ip + '\r\n').encode('utf-8'))
else:
s.send((ip + '\n\n').encode('utf-8'))
time.sleep(2)
resp = s.recv(4096).decode('utf-8')
s.close()
return resp
def parse_response(response, server):
res = []
lines = list(filter(None, response.split('\n')))
for line in lines:
words = list(filter(None, line.split(' ')))
if words[0].startswith(('OriginAS', 'origin', 'aut-num')) and len(words) > 1:
res.append(words[1])
if words[0].startswith(('Country', 'country')) and len(words) > 1:
res.append(words[1])
if words[0].startswith(('OrgName', 'netname')) and len(words) > 1:
res.append(words[1])
res.append('It was')
res.append(server)
return res
def mutate_dictionary(dic):
delete_me = [k for k in dic if any(len(inner) != 5 for inner in dic[k])]
for k in delete_me:
dic[k] = [inner for inner in dic[k] if len(inner) == 5]
return dic
def filter_dictionary(dic):
delete_me = []
for k in dic.keys():
for i in dic[k]:
if not i[2].startswith(('as', 'AS', 'As')):
delete_me.append(i)
for v in dic.values():
for d in delete_me:
if d in v:
v.remove(d)
return dic
def gray(dic):
for k in dic.keys():
if len(dic[k]) == 0:
dic[k] = ('N\\a')
return dic