-
-
Save IceCodeNew/f075bb2025a1e14182270a53011786b5 to your computer and use it in GitHub Desktop.
Revisions
-
k4yt3x revised this gist
Jun 4, 2020 . 1 changed file with 18 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,20 +4,35 @@ ipa is a shell function that will display the distilled informaiton from the `ip a` command. ## Screenshots   ## Usage ```shell ipa # display addresses for all interfaces ipa [INTERFACE] # display address of a given interface ``` ## Code Add this into your shell configuration file (e.g., `~/.bashrc` or `~/.zshrc`). ```shell # ipa prints distilled output of the "ip a" command # version 1.1.0 function ipa() { python3 - $@ << EOF import contextlib, json, subprocess, sys e = ['ip', '-j', 'a'] e.extend(['s', sys.argv[1]]) if len(sys.argv) >= 2 else None s = subprocess.Popen(e, stdout=subprocess.PIPE) j = s.communicate()[0] sys.exit(s.returncode) if s.returncode != 0 else None for i in json.loads(j): with contextlib.suppress(Exception): print('{}: {}'.format(i['ifindex'], i['ifname'])) print(' MAC: {}'.format(i['address'])) if i.get('address') else None -
k4yt3x revised this gist
Jun 4, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ Add this into your shell configuration file (e.g., `~/.bashrc` or `~/.zshrc`). # ipa prints distilled output of the "ip a" command function ipa() { python3 - << EOF import contextlib, json, subprocess, sys for i in json.loads(subprocess.Popen(['ip', '-j', 'a'], stdout=subprocess.PIPE).communicate()[0]): with contextlib.suppress(Exception): print('{}: {}'.format(i['ifindex'], i['ifname'])) -
k4yt3x revised this gist
Jun 4, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ Add this into your shell configuration file (e.g., `~/.bashrc` or `~/.zshrc`). # ipa prints distilled output of the "ip a" command function ipa() { python3 - << EOF import contextlib, json, sys, subprocess for i in json.loads(subprocess.Popen(['ip', '-j', 'a'], stdout=subprocess.PIPE).communicate()[0]): with contextlib.suppress(Exception): print('{}: {}'.format(i['ifindex'], i['ifname'])) -
k4yt3x revised this gist
Jun 4, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ ## Description ipa is a shell function that will display the distilled informaiton from the `ip a` command. ## Screenshot -
k4yt3x revised this gist
Jun 4, 2020 . 1 changed file with 21 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ ## Description ipa is a shell function/alias that will display the distilled informaiton from the `ip a` command. ## Screenshot @@ -12,6 +12,26 @@ ipa is a shell alias that will parse the `ip a` command output, extract useful i Add this into your shell configuration file (e.g., `~/.bashrc` or `~/.zshrc`). ```shell # ipa prints distilled output of the "ip a" command function ipa() { python3 - << EOF import contextlib,json,sys,subprocess for i in json.loads(subprocess.Popen(['ip', '-j', 'a'], stdout=subprocess.PIPE).communicate()[0]): with contextlib.suppress(Exception): print('{}: {}'.format(i['ifindex'], i['ifname'])) print(' MAC: {}'.format(i['address'])) if i.get('address') else None print(' MAC (Permanent): {}'.format(i['permaddr'])) if i.get('permaddr') else None for a in i['addr_info']: family = 'IPv4' if a['family'] == 'inet' else a['family'] family = 'IPv6' if a['family'] == 'inet6' else family print(' {}: {}/{}'.format(family, a['local'], a['prefixlen'])) EOF } ``` Below is the legacy implementation implemented with egrep. It is not recommended. ```shell alias ipa='ip a | egrep --color=never -o "^[0-9]+: ([a-z0-9])+[0-9]*|.*link/(ether|loopback) ([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}|.*inet ([0-9]{1,3}.){3}([0-9]{1,3}/[0-9]{1,2})|.*inet6 (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[0-9]{1,3}" | sed "s/link\/ether/Ethernet:/g" | sed "s/inet6/IPv6:/g" | sed "s/inet/IPv4:/g"' ``` -
k4yt3x revised this gist
Jun 4, 2020 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,16 @@ # ipa ## Description ipa is a shell alias that will parse the `ip a` command output, extract useful information, and display it in a simplified format. ## Screenshot  ## Code Add this into your shell configuration file (e.g., `~/.bashrc` or `~/.zshrc`). ```shell alias ipa='ip a | egrep --color=never -o "^[0-9]+: ([a-z0-9])+[0-9]*|.*link/(ether|loopback) ([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}|.*inet ([0-9]{1,3}.){3}([0-9]{1,3}/[0-9]{1,2})|.*inet6 (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[0-9]{1,3}" | sed "s/link\/ether/Ethernet:/g" | sed "s/inet6/IPv6:/g" | sed "s/inet/IPv4:/g"' -
k4yt3x revised this gist
Jun 4, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@  ```shell alias ipa='ip a | egrep --color=never -o "^[0-9]+: ([a-z0-9])+[0-9]*|.*link/(ether|loopback) ([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}|.*inet ([0-9]{1,3}.){3}([0-9]{1,3}/[0-9]{1,2})|.*inet6 (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[0-9]{1,3}" | sed "s/link\/ether/Ethernet:/g" | sed "s/inet6/IPv6:/g" | sed "s/inet/IPv4:/g"' -
k4yt3x revised this gist
May 25, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@  ```shell alias ipa='ip a | egrep --color=never -o "^[0-9]+: ([a-z0-9])+[0-9]*|.*link/(ether|loopback) ([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}|.*inet ([0-9]{1,3}.){3}([0-9]{1,3}/[0-9]{1,2})|.*inet6 (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[0-9]{1,3}" | sed "s/link\/ether/Ethernet:/g" | sed "s/inet6/IPv6:/g" | sed "s/inet/IPv4:/g"' -
k4yt3x created this gist
May 25, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ ```shell alias ipa='ip a | egrep --color=never -o "^[0-9]+: ([a-z0-9])+[0-9]*|.*link/(ether|loopback) ([a-zA-Z0-9]{2}:){5}[a-zA-Z0-9]{2}|.*inet ([0-9]{1,3}.){3}([0-9]{1,3}/[0-9]{1,2})|.*inet6 (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[0-9]{1,3}" | sed "s/link\/ether/Ethernet:/g" | sed "s/inet6/IPv6:/g" | sed "s/inet/IPv4:/g"' ```