Skip to content

Instantly share code, notes, and snippets.

@devopsy-ir
Last active August 11, 2021 05:14
Show Gist options
  • Save devopsy-ir/b551101415ed43bde082859e68cb5f26 to your computer and use it in GitHub Desktop.
Save devopsy-ir/b551101415ed43bde082859e68cb5f26 to your computer and use it in GitHub Desktop.
Convert port number into the container name and IP
#!/bin/bash
docker ps -q | xargs -n 1 docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{ .Name }}' | sed 's/ \// /' | fgrep $(iptables-save | grep -P "(--to-destination|--.port)" | grep -v "DROP" | grep -P ":\d+|--dport \d+" | fgrep $1 | fgrep -i docker | egrep "to-destination" | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
@devopsy-ir
Copy link
Author

Run by: port-to-container

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