Skip to content

Instantly share code, notes, and snippets.

@a-nldisr
Last active January 19, 2022 11:41
Show Gist options
  • Select an option

  • Save a-nldisr/340f1f3a9cf01c20a7a5687a76ba8cdd to your computer and use it in GitHub Desktop.

Select an option

Save a-nldisr/340f1f3a9cf01c20a7a5687a76ba8cdd to your computer and use it in GitHub Desktop.

Revisions

  1. a-nldisr revised this gist Jan 19, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions get_connection_details.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Some containers do not provide netstat or lsof. This command will get you the local IP a session is established on
    # In short: This gets the output from namespace 1 (where usually the process is running inside the container), filters out the field where the hex IP is located and converts it into a readable IP in the right format. (some fields are inverted etc)
    # Benefit is that you dont need netstat installed to see connections.


    printf '%d.%d.%d.%d\n' $(grep -v local /proc/1/net/tcp | awk '{print $2}'|cut -d: -f1| sed -r 's/(..)/0x\1 /g') | awk -F. '{for (i=NF; i>0; --i) printf "%s%s", (i<NF ? "." : ""), $i; printf "\n"}'

  2. a-nldisr revised this gist Jan 19, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion get_connection_details.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    # Some containers do not provide netstat or lsof. This command will get you the local IP a session is established on
    # In short: This gets the output from namespace 1 (where usually the process is running inside the container), filters out the field where the hex IP is located and converts it into a readable IP in the right format. (some fields are inverted etc)

    printf '%d.%d.%d.%d\n' $(grep -v local /proc/net/tcp | awk '{print $2}'|cut -d: -f1| sed -r 's/(..)/0x\1 /g') | awk -F. '{for (i=NF; i>0; --i) printf "%s%s", (i<NF ? "." : ""), $i; printf "\n"}'
    printf '%d.%d.%d.%d\n' $(grep -v local /proc/1/net/tcp | awk '{print $2}'|cut -d: -f1| sed -r 's/(..)/0x\1 /g') | awk -F. '{for (i=NF; i>0; --i) printf "%s%s", (i<NF ? "." : ""), $i; printf "\n"}'

    # This lists the connections that are established.
    printf '%d.%d.%d.%d\n' $(grep -v rem /proc/1/net/tcp | awk '{print $3}'|cut -d: -f1| sed -r 's/(..)/0x\1 /g') | awk -F. '{for (i=NF; i>0; --i) printf "%s%s", (i<NF ? "." : ""), $i; printf "\n"}'
  3. a-nldisr created this gist Jan 19, 2022.
    8 changes: 8 additions & 0 deletions get_connection_details.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # Some containers do not provide netstat or lsof. This command will get you the local IP a session is established on

    printf '%d.%d.%d.%d\n' $(grep -v local /proc/net/tcp | awk '{print $2}'|cut -d: -f1| sed -r 's/(..)/0x\1 /g') | awk -F. '{for (i=NF; i>0; --i) printf "%s%s", (i<NF ? "." : ""), $i; printf "\n"}'

    # This lists the connections that are established.
    printf '%d.%d.%d.%d\n' $(grep -v rem /proc/1/net/tcp | awk '{print $3}'|cut -d: -f1| sed -r 's/(..)/0x\1 /g') | awk -F. '{for (i=NF; i>0; --i) printf "%s%s", (i<NF ? "." : ""), $i; printf "\n"}'

    # It could be shorter..