- Support and report resolver failure by using default IP addresses,
- Simple code refactoring.
This commit is contained in:
parent
5cbbad8b8b
commit
bd7786b904
@ -2,7 +2,8 @@ Welcome to Rx3 MyIP!
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
This is a small tool to return the extern public IP address and optionnally the internal private IP,
|
This is a small tool to return the extern public IP address and optionnally the internal private IP.
|
||||||
|
Support missing name resolver by using default IP addresses.
|
||||||
The internal IP service is also included.
|
The internal IP service is also included.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
MyIP V 1.2.0 - A. GIBERT - 2025/09/18
|
||||||
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Support and report resolver failure by using default IP addresses,
|
||||||
|
- Simple code refactoring.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
MyIP V 1.1.0 - A. GIBERT - 2025/09/09
|
MyIP V 1.1.0 - A. GIBERT - 2025/09/09
|
||||||
------------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
%define name myip
|
%define name myip
|
||||||
%define version 1.1.0
|
%define version 1.2.0
|
||||||
%define release %mkrel 1rx3
|
%define release %mkrel 1rx3
|
||||||
|
|
||||||
%global debug_package %{nil}
|
%global debug_package %{nil}
|
||||||
|
|
||||||
|
%global _webdir %{_localstatedir}/www
|
||||||
|
%global _webcgi %{_webdir}/cgi-bin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Name: %{name}
|
Name: %{name}
|
||||||
Version: %{version}
|
Version: %{version}
|
||||||
Release: %{release}
|
Release: %{release}
|
||||||
Summary: Simple script to get your public IP
|
Summary: Simple script to get your public and private IP addresses
|
||||||
License: GPL
|
License: GPL
|
||||||
URL: https://git.rx3.org/gitea/rx3/myip
|
URL: https://git.rx3.org/gitea/rx3/myip
|
||||||
|
|
||||||
Source0: myip
|
Source0: %{name}-%{version}.tar.bz2
|
||||||
|
|
||||||
Distribution: Rx3 Free Software
|
Distribution: Rx3 Free Software
|
||||||
Vendor: Rx3
|
Vendor: Rx3
|
||||||
@ -22,12 +27,12 @@ Requires: bind-utils
|
|||||||
|
|
||||||
|
|
||||||
%description
|
%description
|
||||||
Simple script to get your public IP.
|
Simple script to get your public and private IP.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
cp %{SOURCE0} .
|
%setup -q -n %{name}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -36,7 +41,8 @@ cp %{SOURCE0} .
|
|||||||
|
|
||||||
|
|
||||||
%install
|
%install
|
||||||
install -D -pm 755 %{name} $RPM_BUILD_ROOT%{_bindir}/%{name}
|
install -D -pm 755 bin/%{name} %{buildroot}%{_bindir}/%{name}
|
||||||
|
install -D -pm 755 var/www/cgi-bin/%{name}.cgi %{buildroot}%{_webcgi}/%{name}.cgi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -45,11 +51,17 @@ install -D -pm 755 %{name} $RPM_BUILD_ROOT%{_bindir}/%{name}
|
|||||||
|
|
||||||
|
|
||||||
%files
|
%files
|
||||||
|
%doc ReadMe.txt ReleaseNotes.txt
|
||||||
|
%license GNU_GPL-3.0.txt GNU_LGPL-3.0.txt GNU_FDL-1.3.txt
|
||||||
%{_bindir}/%{name}
|
%{_bindir}/%{name}
|
||||||
|
%{_webcgi}/%{name}.cgi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Thu Sep 18 2025 Arnaud G. GIBERT <arnaud@rx3.net> - 1.2.0-1rx3.mga9
|
||||||
|
- Update to 1.2.0
|
||||||
|
|
||||||
* Tue Sep 9 2025 Arnaud G. GIBERT <arnaud@rx3.net> - 1.1.0-1rx3.mga9
|
* Tue Sep 9 2025 Arnaud G. GIBERT <arnaud@rx3.net> - 1.1.0-1rx3.mga9
|
||||||
- Update to 1.1.0
|
- Update to 1.1.0
|
||||||
|
|
130
bin/myip
130
bin/myip
@ -1,4 +1,79 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# MyIP
|
||||||
|
# Copyright (C) 2025 Arnaud G. GIBERT
|
||||||
|
# mailto:arnaud@rx3.net
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
WEB_SERVER_NAME="www.rx3"
|
||||||
|
WEB_SERVER_IP="10.0.0.65"
|
||||||
|
|
||||||
|
RESOLVER_NAME="resolver1.opendns.com"
|
||||||
|
RESOLVER_IP="208.67.222.222"
|
||||||
|
|
||||||
|
declare -g RESOLV_STATUS="OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
# ip_filter
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ip_filter()
|
||||||
|
{
|
||||||
|
grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
# resolv
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
resolv()
|
||||||
|
{
|
||||||
|
local host_name="$1"
|
||||||
|
local host_ip="$2"
|
||||||
|
|
||||||
|
|
||||||
|
resolv_ip="$( dig +short "${host_name}" | ip_filter)"
|
||||||
|
|
||||||
|
if [[ "${resolv_ip}" == "" ]]
|
||||||
|
then
|
||||||
|
RESOLV_STATUS="KO"
|
||||||
|
resolv_ip="${host_ip=}"
|
||||||
|
else
|
||||||
|
RESOLV_STATUS="OK"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
# main
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
if [[ "$1" == "-h" ]]
|
if [[ "$1" == "-h" ]]
|
||||||
then
|
then
|
||||||
@ -9,44 +84,61 @@ then
|
|||||||
else
|
else
|
||||||
if [[ "$1" == "-a" ]]
|
if [[ "$1" == "-a" ]]
|
||||||
then
|
then
|
||||||
INT_FLAG="TRUE"
|
int_flag="TRUE"
|
||||||
EXT_FLAG="TRUE"
|
ext_flag="TRUE"
|
||||||
VERBOSE_FLAG="TRUE"
|
verbose_flag="TRUE"
|
||||||
else
|
else
|
||||||
VERBOSE_FLAG="FALSE"
|
verbose_flag="FALSE"
|
||||||
|
|
||||||
if [[ "$1" == "-i" ]]
|
if [[ "$1" == "-i" ]]
|
||||||
then
|
then
|
||||||
INT_FLAG="TRUE"
|
int_flag="TRUE"
|
||||||
EXT_FLAG="FALSE"
|
ext_flag="FALSE"
|
||||||
else
|
else
|
||||||
INT_FLAG="FALSE"
|
int_flag="FALSE"
|
||||||
EXT_FLAG="TRUE"
|
ext_flag="TRUE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ ${VERBOSE_FLAG} == "TRUE" ]]
|
|
||||||
|
if [[ ${verbose_flag} == "TRUE" ]]
|
||||||
then
|
then
|
||||||
INT_LABEL="internal_ip: "
|
int_label="Internal IP: "
|
||||||
EXT_LABEL="external_ip: "
|
ext_label="External IP: "
|
||||||
else
|
else
|
||||||
INT_LABEL=""
|
int_label=""
|
||||||
EXT_LABEL=""
|
ext_label=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ ${INT_FLAG} == "TRUE" ]]
|
if [[ ${int_flag} == "TRUE" ]]
|
||||||
then
|
then
|
||||||
INT_IP="$( curl -s http://www.rx3/cgi-bin/myip.cgi | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$')"
|
resolv "${WEB_SERVER_NAME}" "${WEB_SERVER_IP}"
|
||||||
|
web_server_ip="${resolv_ip}"
|
||||||
|
|
||||||
echo "${INT_LABEL}${INT_IP}"
|
int_ip="$( curl --resolve ${WEB_SERVER_NAME}:80:${web_server_ip} -s http://www.rx3/cgi-bin/myip.cgi | ip_filter)"
|
||||||
|
|
||||||
|
if [[ ( "${int_label}" != "") && ( "${RESOLV_STATUS}" != "OK") ]]
|
||||||
|
then
|
||||||
|
echo "Warning: resolver failed for [${WEB_SERVER_NAME}], using default address: [${WEB_SERVER_IP}]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${int_label}${int_ip}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${EXT_FLAG} == "TRUE" ]]
|
if [[ ${ext_flag} == "TRUE" ]]
|
||||||
then
|
then
|
||||||
EXT_IP="$( dig +short myip.opendns.com @resolver1.opendns.com | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$')"
|
resolv "${RESOLVER_NAME}" "${RESOLVER_IP}"
|
||||||
|
resolver_ip="${resolv_ip}"
|
||||||
|
|
||||||
echo "${EXT_LABEL}${EXT_IP}"
|
ext_ip="$( dig +short myip.opendns.com @${resolver_ip} | ip_filter)"
|
||||||
|
|
||||||
|
if [[ ( "${ext_label}" != "") && ( "${RESOLV_STATUS}" != "OK") ]]
|
||||||
|
then
|
||||||
|
echo "Warning: resolver failed for [${RESOLVER_NAME}], using default address: [${RESOLVER_IP}]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${ext_label}${ext_ip}"
|
||||||
fi
|
fi
|
||||||
|
@ -1,5 +1,29 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# MyIP.CGI
|
||||||
|
# Copyright (C) 2025 Arnaud G. GIBERT
|
||||||
|
# mailto:arnaud@rx3.net
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo "Content-type: text/plain"
|
echo "Content-type: text/plain"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo "$REMOTE_ADDR"
|
echo "${REMOTE_ADDR}"
|
||||||
|
Loading…
Reference in New Issue
Block a user