Skip to content

Instantly share code, notes, and snippets.

@scentoni
Last active April 7, 2022 19:28
Show Gist options
  • Save scentoni/3b0a146d6c95456bbe8dfa7ed830436b to your computer and use it in GitHub Desktop.
Save scentoni/3b0a146d6c95456bbe8dfa7ed830436b to your computer and use it in GitHub Desktop.
hostify: try to translate everything that looks like IP addresses
#!/usr/bin/perl
# hostify: try to translate everything that looks like IP addresses
# into hostnames. Leave them alone if DNS doesn't resolve them.
# echo "Please tip your 127.0.0.1 well." |hostify
# Please tip your localhost well.
use Socket;
sub host { return gethostbyaddr(inet_aton($_[0]), AF_INET) // $_[0]}
while(<>){
# s/(\d+\.\d+\.\d+\.\d+)/host $1/ge;
s/((\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})/host $1/ge;
print $_;
}
@scentoni
Copy link
Author

scentoni commented Apr 7, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment