Skip to content

Instantly share code, notes, and snippets.

@IceCodeNew
Forked from k4yt3x/ipa.md
Created June 16, 2020 04:54
Show Gist options
  • Save IceCodeNew/f075bb2025a1e14182270a53011786b5 to your computer and use it in GitHub Desktop.
Save IceCodeNew/f075bb2025a1e14182270a53011786b5 to your computer and use it in GitHub Desktop.

Revisions

  1. @k4yt3x k4yt3x revised this gist Jun 4, 2020. 1 changed file with 18 additions and 3 deletions.
    21 changes: 18 additions & 3 deletions ipa.md
    Original 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.

    ## Screenshot
    ## Screenshots

    ![ipa screenshot](https://user-images.githubusercontent.com/21986859/83730560-c7483900-a638-11ea-89c9-d73b9ead1e45.png)

    ![single interface](https://user-images.githubusercontent.com/21986859/83795016-5c295180-a68e-11ea-9679-135b71b8a0ab.png)

    ## 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
    python3 - $@ << EOF
    import contextlib, json, subprocess, sys
    for i in json.loads(subprocess.Popen(['ip', '-j', 'a'], stdout=subprocess.PIPE).communicate()[0]):
    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
  2. @k4yt3x k4yt3x revised this gist Jun 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ipa.md
    Original 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
    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']))
  3. @k4yt3x k4yt3x revised this gist Jun 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ipa.md
    Original 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
    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']))
  4. @k4yt3x k4yt3x revised this gist Jun 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ipa.md
    Original 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.
    ipa is a shell function that will display the distilled informaiton from the `ip a` command.

    ## Screenshot

  5. @k4yt3x k4yt3x revised this gist Jun 4, 2020. 1 changed file with 21 additions and 1 deletion.
    22 changes: 21 additions & 1 deletion ipa.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    ## Description

    ipa is a shell alias that will parse the `ip a` command output, extract useful information, and display it in a simplified format.
    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"'
    ```
  6. @k4yt3x k4yt3x revised this gist Jun 4, 2020. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion ipa.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,16 @@
    ![image](https://user-images.githubusercontent.com/21986859/83730560-c7483900-a638-11ea-89c9-d73b9ead1e45.png)
    # 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

    ![ipa screenshot](https://user-images.githubusercontent.com/21986859/83730560-c7483900-a638-11ea-89c9-d73b9ead1e45.png)

    ## 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"'
  7. @k4yt3x k4yt3x revised this gist Jun 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ipa.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ![image](https://user-images.githubusercontent.com/21986859/82768217-28903100-9e1d-11ea-8448-0ed5509866da.png)
    ![image](https://user-images.githubusercontent.com/21986859/83730560-c7483900-a638-11ea-89c9-d73b9ead1e45.png)

    ```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"'
  8. @k4yt3x k4yt3x revised this gist May 25, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ipa.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    ![image](https://user-images.githubusercontent.com/21986859/82768217-28903100-9e1d-11ea-8448-0ed5509866da.png)

    ```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"'
  9. @k4yt3x k4yt3x created this gist May 25, 2020.
    4 changes: 4 additions & 0 deletions ipa.md
    Original 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"'
    ```