-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatters.py
More file actions
32 lines (26 loc) · 931 Bytes
/
Copy pathFormatters.py
File metadata and controls
32 lines (26 loc) · 931 Bytes
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
import re
class IPDomainNameChecker:
@staticmethod
def check(address):
if not (IPDomainNameChecker.check_ip(address) or IPDomainNameChecker.check_domain_name(address)):
raise Exception("Invalid address")
@staticmethod
def check_ip(ip):
return re.match(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", ip)
@staticmethod
def check_domain_name(name):
return re.match(r"^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$", name)
class TraceFormatter:
@staticmethod
def format_trace(trace):
for line in trace:
line = line[4:]
if len(line) < 1:
break
if line[0] == "*":
yield " * * * ", " * * * "
break
splited_line = line.split(" ")
domain = splited_line[0]
ip = splited_line[1].strip("(").strip(")")
yield domain, ip