From e1fa9f09e93264fd2315062d034df8731759bea5 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Tue, 9 Sep 2025 18:52:46 +0200 Subject: [PATCH] - Add internal IP reporting to myip command, - Add internal IP service CGI script. --- ReadMe.txt | 3 ++- ReleaseNotes.txt | 8 +++++++ bin/myip | 51 +++++++++++++++++++++++++++++++++++++++- var/www/cgi-bin/myip.cgi | 5 ++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100755 var/www/cgi-bin/myip.cgi diff --git a/ReadMe.txt b/ReadMe.txt index 75244d3..6ede2a1 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -2,7 +2,8 @@ Welcome to Rx3 MyIP! -This is a small tool to return the public IP address. +This is a small tool to return the extern public IP address and optionnally the internal private IP, +The internal IP service is also included. diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 5cf7b80..1d05e9b 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,3 +1,11 @@ +------------------------------------------------------------------------------------------------------------------------------------ +MyIP V 1.1.0 - A. GIBERT - 2025/09/09 +------------------------------------------------------------------------------------------------------------------------------------ + +- Add internal IP reporting to myip command, +- Add internal IP service CGI script. + + ------------------------------------------------------------------------------------------------------------------------------------ MyIP V 1.0.1 - A. GIBERT - 2025/07/26 diff --git a/bin/myip b/bin/myip index 0255724..8d18fd7 100755 --- a/bin/myip +++ b/bin/myip @@ -1,3 +1,52 @@ #!/bin/bash -dig +short myip.opendns.com @resolver1.opendns.com | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' +if [[ "$1" == "-h" ]] +then + echo "myip [-i] | [-a] | [-h]" + echo "default: external IP" + echo " -i: internal IP" + echo " -a: internal + external IP" +else + if [[ "$1" == "-a" ]] + then + INT_FLAG="TRUE" + EXT_FLAG="TRUE" + VERBOSE_FLAG="TRUE" + else + VERBOSE_FLAG="FALSE" + + if [[ "$1" == "-i" ]] + then + INT_FLAG="TRUE" + EXT_FLAG="FALSE" + else + INT_FLAG="FALSE" + EXT_FLAG="TRUE" + fi + fi +fi + + +if [[ ${VERBOSE_FLAG} == "TRUE" ]] +then + INT_LABEL="internal_ip: " + EXT_LABEL="external_ip: " +else + INT_LABEL="" + EXT_LABEL="" +fi + + +if [[ ${INT_FLAG} == "TRUE" ]] +then + INT_IP="$( curl -s http://www.rx3/cgi-bin/myip.cgi | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$')" + + echo "${INT_LABEL}${INT_IP}" +fi + +if [[ ${EXT_FLAG} == "TRUE" ]] +then + EXT_IP="$( dig +short myip.opendns.com @resolver1.opendns.com | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$')" + + echo "${EXT_LABEL}${EXT_IP}" +fi diff --git a/var/www/cgi-bin/myip.cgi b/var/www/cgi-bin/myip.cgi new file mode 100755 index 0000000..ac3d336 --- /dev/null +++ b/var/www/cgi-bin/myip.cgi @@ -0,0 +1,5 @@ +#!/bin/sh +echo "Content-type: text/plain" +echo "" + +echo "$REMOTE_ADDR"