checkIpAddress.sh 265 B

12345678910111213
  1. #!/bin/sh
  2. if [ "$1" = "public" ]; then
  3. ip=$(curl --silent --connect-timeout 1 ifconfig.me)
  4. elif [ "$1" = "private" ]; then
  5. ip=$(ifconfig -a | grep "inet 192.168." | awk '{print $2}' | head -1)
  6. fi
  7. if [ -n "$ip" ]; then
  8. echo "$ip"
  9. else
  10. echo "n/a"
  11. fi