-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathip2domain.py
39 lines (33 loc) · 1002 Bytes
/
ip2domain.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
#Syntax: python3 new2.py filepath/augurynetflowfile
import socket
import ssl
import OpenSSL.crypto as crypto
import sys
import re
f = open(sys.argv[1],'r')
text = f.read()
ips = []
regex = re.findall(r'\b(?:\d{1,3}\.){3}\d{1,3}\b',text)
if regex is not None:
for match in regex:
if match not in ips:
ips.append(match)
for ip in ips:
try:
dst = (ip,443)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.connect(dst)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
s = ctx.wrap_socket(s, server_hostname=dst[0])
# get certificate
cert_bin = s.getpeercert(True)
x509 = crypto.load_certificate(crypto.FILETYPE_ASN1,cert_bin)
print("IP: " +str(ip) + " || Cert name: "+ x509.get_subject().CN)
except socket.error:
print("IP: " +str(ip) + " || No cert")
continue
else:
continue