Created
November 22, 2022 11:51
-
-
Save bmcbm/5402b223694b850f4e9167a0a9a7e084 to your computer and use it in GitHub Desktop.
Aliases to defang and "refang" IP-addresses and domains in Linux bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Aliases to defang IP-addresses/domains and remove the defanging again - "refang" for lack of a better word. | |
# | |
# Add the aliases to ~/.bash_aliases | |
# Then source the file: source ~/.bash_aliases | |
# | |
# Takes arguments from command line or STDIN (one per line) | |
# | |
# Examples: | |
# | |
# $ defang 1.2.3.4 2.2.3.3 www.google.com | |
# 1.2.3[.]4 | |
# 2.2.3[.]3 | |
# www.google[.]com | |
# | |
# $ defang 1.2.3.4 2.2.3.3 | refang | |
# 1.2.3.4 | |
# 2.2.3.3 | |
# www.google.com | |
alias defang="perl -e 'foreach(@ARGV) {s/\.(\w+)$/\[.\]\$1/; print \"\$_\n\"} unless (-t) { while(<STDIN>){s/\.(\w+)$/\[.\]\$1/; print}}'" | |
alias refang="perl -e 'foreach(@ARGV) {s/[\[\]]//g; print \"\$_\n\"} unless (-t) { while(<STDIN>){s/[\[\]]//g; print}}'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment