nathandines / spf2ip Goto Github PK
View Code? Open in Web Editor NEWPython module which extracts all IP addresses from an SPF record and outputs them in CIDR format
License: MIT License
Python module which extracts all IP addresses from an SPF record and outputs them in CIDR format
License: MIT License
I just saw this in an spf record:
# dig -t TXT sendgrid.com|grep spf1
sendgrid.com. 264 IN TXT "v=spf1 include:sendgrid.com._nspf.vali.email include:%{i}._ip.%{h}._ehlo.%{d}._spf.vali.email include:stspg-customer.com ~all"
So I started searching in https://tools.ietf.org/html/rfc7208 and lo and behold: 7.3. Macro Processing Details show there is a complete macro processing ruleset in spf. Is that supported in SPF2IP?
For example:
# SPF2IP --domain linkedin.com --ip-version 4
Traceback (most recent call last):
File "/usr/local/bin/SPF2IP", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/dist-packages/SPF2IP.py", line 169, in main
for ip in lookup.IPArray(args.ip_version):
File "/usr/local/lib/python3.6/dist-packages/SPF2IP.py", line 70, in IPArray
NewIncludes = self.FindIncludes(domain)
File "/usr/local/lib/python3.6/dist-packages/SPF2IP.py", line 84, in FindIncludes
entries = self.GetSPFArray(domain)
File "/usr/local/lib/python3.6/dist-packages/SPF2IP.py", line 94, in GetSPFArray
results = dns_request_unicode(domain,'TXT')
File "/usr/local/lib/python3.6/dist-packages/SPF2IP.py", line 17, in dns_request_unicode
result = dns.resolver.query(hostname,record_type,*args,**kwargs)
File "/usr/local/lib/python3.6/dist-packages/dns/resolver.py", line 1223, in query
True)
File "/usr/local/lib/python3.6/dist-packages/dns/resolver.py", line 1207, in resolve
lifetime, search)
File "/usr/local/lib/python3.6/dist-packages/dns/resolver.py", line 1040, in resolve
(nameserver, port, tcp, backoff) = resolution.next_nameserver()
File "/usr/local/lib/python3.6/dist-packages/dns/resolver.py", line 598, in next_nameserver
raise NoNameservers(request=self.request, errors=self.errors)
dns.resolver.NoNameservers: All nameservers failed to answer the query linkedin.com. IN TXT: Server 10.10.10.11 UDP port 53 answered ; Server 10.10.10.11 TCP port 53 answered [Errno 111] Connection refused; Server 10.10.10.12 UDP port 53 answered ; Server 10.10.10.12 TCP port 53 answered [Errno 111] Connection refused
I somewhat suspect this problem might be caused by the unbound nameservers that don't like all these recursions, but I checked the config and rate limiting is disabled. So my question is, can you repeat this or is this a local problem?
The current code always returns an empty answer on Python 3.6. This fixes it for me:
diff --git a/SPF2IP.py b/SPF2IP.py
index e6210f3..84683ff 100644
--- a/SPF2IP.py
+++ b/SPF2IP.py
@@ -34,7 +34,7 @@ def dns_request_unicode(hostname,record_type,*args,**kwargs):
value = value.__str__().encode('utf-8').decode('utf-8')
output.append(value)
elif record_type == "TXT":
- value = ''.join([str(ent) for ent in entry.strings])
+ value = ''.join([str(ent, encoding='ascii') for ent in entry.strings])
if type(value) is not unicode:
value = value.decode('utf-8')
output.append(value)
I only know python3 so I can't give good advice on making code that works on both 2 and 3. But a friend of mine's package has this function that you might find useful:
def to_native_str(value, encoding='utf-8'):
if isinstance(value, str):
return value
if six.PY3 and isinstance(value, six.binary_type): #pragma: no cover
return value.decode(encoding)
elif six.PY2 and isinstance(value, six.text_type): #pragma: no cover
return value.encode(encoding)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.