Compare commits
2 commits
main
...
parse_spf_
| Author | SHA1 | Date | |
|---|---|---|---|
| 369137ae99 | |||
| 013c0ea4d4 |
3 changed files with 47 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -162,3 +162,4 @@ cython_debug/
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
/.idea/
|
||||||
|
|
|
||||||
10
.idea/pymsgcheck.iml
generated
Normal file
10
.idea/pymsgcheck.iml
generated
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.12 (pymsgcheck)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
36
pymsgcheck.py
Normal file
36
pymsgcheck.py
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
from os.path import split
|
||||||
|
import dns.resolver
|
||||||
|
import ipaddress
|
||||||
|
|
||||||
|
|
||||||
|
def parse_spf_parts(part):
|
||||||
|
if part.startswith('ip4:'):
|
||||||
|
return [part[4:]]
|
||||||
|
elif part.startswith('ip6:'):
|
||||||
|
return [part[4:]]
|
||||||
|
elif part.startswith('include'):
|
||||||
|
return get_spf_record(part[8:])
|
||||||
|
elif part.startswith('a'):
|
||||||
|
addresses = []
|
||||||
|
for address in dns.resolver.resolve_name(part[2:]).addresses():
|
||||||
|
addresses.append(address)
|
||||||
|
return addresses
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def get_spf_record(domain_name):
|
||||||
|
spf_record = ''
|
||||||
|
servers = []
|
||||||
|
txt_records = dns.resolver.resolve(domain_name, 'TXT')
|
||||||
|
for record in txt_records:
|
||||||
|
if record.to_text().find('v=spf1') > 0:
|
||||||
|
spf_record = record.to_text()
|
||||||
|
parts = spf_record.split()
|
||||||
|
for part in parts:
|
||||||
|
servers += (parse_spf_parts(part))
|
||||||
|
return servers
|
||||||
|
|
||||||
|
|
||||||
|
spf_servers = get_spf_record('trivago.com')
|
||||||
|
print(spf_servers)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue