Compare commits
4 Commits
myip-1.0.0
...
myip-1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 276ce11f80 | |||
| 5cbbad8b8b | |||
| e1fa9f09e9 | |||
| 15b28c8f43 |
@@ -2,7 +2,9 @@ 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.
|
||||||
|
Support missing name resolver by using default IP addresses.
|
||||||
|
The internal IP service is also included.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,29 @@
|
|||||||
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
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
|
||||||
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Add internal IP reporting to myip command,
|
||||||
|
- Add internal IP service CGI script.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
MyIP V 1.0.1 - A. GIBERT - 2025/07/26
|
||||||
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Filter output to remove errors and only keep IP
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
MyIP V 1.0.0 - A. GIBERT - 2025/04/25
|
MyIP V 1.0.0 - A. GIBERT - 2025/04/25
|
||||||
------------------------------------------------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
%define name myip
|
|
||||||
%define version 1.0.0
|
|
||||||
%define release %mkrel 1rx3
|
|
||||||
|
|
||||||
%global debug_package %{nil}
|
|
||||||
|
|
||||||
Name: %{name}
|
|
||||||
Version: %{version}
|
|
||||||
Release: %{release}
|
|
||||||
Summary: Simple script to get your public IP
|
|
||||||
License: GPL
|
|
||||||
URL: https://git.rx3.org/gitea/rx3/myip
|
|
||||||
|
|
||||||
Source0: myip
|
|
||||||
|
|
||||||
Distribution: Rx3 Free Software
|
|
||||||
Vendor: Rx3
|
|
||||||
Packager: Arnaud G. GIBERT <arnaud@rx3.net>
|
|
||||||
|
|
||||||
Requires: bind-utils
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%description
|
|
||||||
Simple script to get your public IP.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%prep
|
|
||||||
cp %{SOURCE0} .
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%build
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%install
|
|
||||||
install -D -pm 755 %{name} $RPM_BUILD_ROOT%{_bindir}/%{name}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%check
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%files
|
|
||||||
%{_bindir}/%{name}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%changelog
|
|
||||||
* Sun Apr 6 2025 Arnaud G. GIBERT <arnaud@rx3.net> - 1.0.0-1rx3.mga9
|
|
||||||
- Create initial SPEC file for 1.0.0 on Mageia 9
|
|
||||||
72
SPECS/myip.spec
Normal file
72
SPECS/myip.spec
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
%define name myip
|
||||||
|
%define version 1.2.0
|
||||||
|
%define release %mkrel 1rx3
|
||||||
|
|
||||||
|
%global debug_package %{nil}
|
||||||
|
|
||||||
|
%global _webdir %{_localstatedir}/www
|
||||||
|
%global _webcgi %{_webdir}/cgi-bin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Name: %{name}
|
||||||
|
Version: %{version}
|
||||||
|
Release: %{release}
|
||||||
|
Summary: Simple script to get your public and private IP addresses
|
||||||
|
License: GPL
|
||||||
|
URL: https://git.rx3.org/gitea/rx3/myip
|
||||||
|
|
||||||
|
Source0: %{name}-%{version}.tar.bz2
|
||||||
|
|
||||||
|
Distribution: Rx3 Free Software
|
||||||
|
Vendor: Rx3
|
||||||
|
Packager: Arnaud G. GIBERT <arnaud@rx3.net>
|
||||||
|
|
||||||
|
Requires: bind-utils
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%description
|
||||||
|
Simple script to get your public and private IP.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%setup -q -n %{name}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%build
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%install
|
||||||
|
install -D -pm 755 bin/%{name} %{buildroot}%{_bindir}/%{name}
|
||||||
|
install -D -pm 755 var/www/cgi-bin/%{name}.cgi %{buildroot}%{_webcgi}/%{name}.cgi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%check
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%files
|
||||||
|
%doc ReadMe.txt ReleaseNotes.txt
|
||||||
|
%license GNU_GPL-3.0.txt GNU_LGPL-3.0.txt GNU_FDL-1.3.txt
|
||||||
|
%{_bindir}/%{name}
|
||||||
|
%{_webcgi}/%{name}.cgi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%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
|
||||||
|
- Update to 1.1.0
|
||||||
|
|
||||||
|
* Sat Jul 26 2025 Arnaud G. GIBERT <arnaud@rx3.net> - 1.0.1-1rx3.mga9
|
||||||
|
- Filter output to remove errors and only keep IP
|
||||||
|
|
||||||
|
* Sun Apr 6 2025 Arnaud G. GIBERT <arnaud@rx3.net> - 1.0.0-1rx3.mga9
|
||||||
|
- Create initial SPEC file for 1.0.0 on Mageia 9
|
||||||
143
bin/myip
143
bin/myip
@@ -1,3 +1,144 @@
|
|||||||
#!/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.
|
||||||
|
#
|
||||||
|
#-----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
dig +short myip.opendns.com @resolver1.opendns.com
|
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" ]]
|
||||||
|
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
|
||||||
|
resolv "${WEB_SERVER_NAME}" "${WEB_SERVER_IP}"
|
||||||
|
web_server_ip="${resolv_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
|
||||||
|
|
||||||
|
if [[ ${ext_flag} == "TRUE" ]]
|
||||||
|
then
|
||||||
|
resolv "${RESOLVER_NAME}" "${RESOLVER_IP}"
|
||||||
|
resolver_ip="${resolv_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
|
||||||
|
|||||||
29
var/www/cgi-bin/myip.cgi
Executable file
29
var/www/cgi-bin/myip.cgi
Executable file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/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 ""
|
||||||
|
|
||||||
|
echo "${REMOTE_ADDR}"
|
||||||
Reference in New Issue
Block a user