jetmore / swaks

Swaks - Swiss Army Knife for SMTP
http://jetmore.org/john/code/swaks/
GNU General Public License v2.0
847 stars 86 forks source link

Add option to always look up and use the hostname of the public IP #75

Open jetmore opened 7 months ago

jetmore commented 7 months ago

This was requested via email by stembera.jan0#seznam.cz. I initially rejected it but after seeing how easy it is to do with DNS and thinking about it a bit, this is actually a pretty good fit for the proposed MUA mode

work around for now:

# get my public IP
dig +short myip.opendns.com @resolver1.opendns.com

# Then flip this around to get the public hostname for that IP:
dig +short -x `dig +short myip.opendns.com @resolver1.opendns.com`

# then strip the trailing period off of the response:
dig +short -x `dig +short myip.opendns.com @resolver1.opendns.com` | sed 's/\.$//'

if you saved that in a shell script you could then add "--helo `get-public-hostname.pl`" to the swaks command line
jetmore commented 6 months ago

Jan refined this

dig @ns.sslip.io txt ip.sslip.io +short | sed 's/:/-/g' | sed 's/"//g' | sed 's/$/.sslip.io/'

This returns something like 1.2.3.4.sslip.io. This means there could be yet another path for what someone wants the hostname to be:

jetmore commented 6 months ago

One way to implement this would be to look at the IP we're connecting to (after we make the connection, since we might not have an IP before the connection) and, if it's RFC1918, use the local hostname as we always have. But if it's not, then use the "find my public hostname" method above. This might be too clever though. And I don't think there's an rfc1918 equiv for ipv6.