Compare commits
4 Commits
myip-1.0.1
...
myip-1.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 33bf6f7507 | |||
| 276ce11f80 | |||
| 5cbbad8b8b | |||
| e1fa9f09e9 |
@@ -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.1 - A. GIBERT - 2026/04/22
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
- Migrate to Rx3 base libray 1.1.2,
|
||||
- Add bash completion script.
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
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
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
%define name myip
|
||||
%define version 1.0.1
|
||||
%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
|
||||
* 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
|
||||
139
SPECS/myip.spec
Normal file
139
SPECS/myip.spec
Normal file
@@ -0,0 +1,139 @@
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# MyIP
|
||||
#
|
||||
# Copyright (C) 2025-2026 Arnaud G. GIBERT
|
||||
# mailto:arnaud@rx3.net
|
||||
#
|
||||
# This is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
%define name myip
|
||||
%define version 1.2.1
|
||||
%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/%{name}
|
||||
|
||||
Source0: https://git.rx3.org/gitea/rx3/%{name}/archive/%{name}-%{version}.tar.gz
|
||||
|
||||
Distribution: Rx3 Free Software
|
||||
Vendor: Rx3
|
||||
Packager: Arnaud G. GIBERT <arnaud@rx3.net>
|
||||
|
||||
BuildArch: noarch
|
||||
|
||||
Requires: network_tools-libs
|
||||
|
||||
|
||||
|
||||
%description
|
||||
Simple script to get your public and private IP.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Prep
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
%prep
|
||||
%setup -q -n %{name}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Build
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
%build
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Install
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
%install
|
||||
install -D -pm 644 etc/bash_completion.d/%{name} %{buildroot}%{_sysconfdir}/bash_completion.d/%{name}
|
||||
install -D -pm 755 bin/%{name} %{buildroot}%{_bindir}/%{name}
|
||||
install -D -pm 755 www/cgi-bin/%{name}.cgi %{buildroot}%{_webcgi}/%{name}.cgi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Check
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
%check
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Files
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
%files
|
||||
%doc ReadMe.txt ReleaseNotes.txt ToDo.txt
|
||||
%license GNU_GPL-3.0.txt GNU_LGPL-3.0.txt GNU_FDL-1.3.txt
|
||||
%{_sysconfdir}/bash_completion.d/%{name}
|
||||
%{_bindir}/%{name}
|
||||
%{_webcgi}/%{name}.cgi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# ChangeLog
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
%%changelog
|
||||
* Tue Apr 21 2026 Arnaud G. GIBERT <arnaud@rx3.net> - 1.2.1-1rx3.mga9
|
||||
- Update to 1.2.1
|
||||
- Add bash completion script
|
||||
|
||||
* 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
|
||||
245
bin/myip
245
bin/myip
@@ -1,3 +1,246 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# MyIP
|
||||
#
|
||||
# Copyright (C) 2025-2026 Arnaud G. GIBERT
|
||||
# mailto:arnaud@rx3.net
|
||||
#
|
||||
# This is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
dig +short myip.opendns.com @resolver1.opendns.com | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Includes
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
: "${RX3_LIB_DIR:=/usr/lib/rx3}"
|
||||
. "${RX3_LIB_DIR}/network.bash"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Global Variables
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
declare -g VERSION="1.2.1"
|
||||
declare -g NAME="MyIP"
|
||||
declare -g HELP="usage: [-h | --help] | [-V | --version] | [-i | --internal] | [-a | --all] [-T | --test] [-v | --verbose] "
|
||||
|
||||
declare -g MODE="EXTERNAL"
|
||||
declare -g VERBOSE="FALSE"
|
||||
declare -g DRY_RUN="FALSE"
|
||||
declare -g RETVAL=0
|
||||
|
||||
declare -g WEB_SERVER_NAME="www.rx3"
|
||||
declare -g WEB_SERVER_IP="10.0.0.65"
|
||||
declare -g WEB_SERVER_URL="http://www.rx3/cgi-bin/myip.cgi"
|
||||
|
||||
declare -g RESOLVER_NAME="resolver1.opendns.com"
|
||||
declare -g RESOLVER_IP="208.67.222.222"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Version Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
myip_version_print()
|
||||
{
|
||||
version_print
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Help Print
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
myip_help_print()
|
||||
{
|
||||
myip_version_print
|
||||
help_print
|
||||
echo " default: external IP"
|
||||
echo " -i: internal IP"
|
||||
echo " -a: internal + external IP"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Arg Parse
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
myip_args_parse()
|
||||
{
|
||||
tmp_args=$(getopt -o ahiTvV --long all,help,internal,test,verbose,version -n "${NAME}" -- "$@")
|
||||
|
||||
if [ $? != 0 ]; then echo_error "Terminating..."; exit 1; fi
|
||||
|
||||
eval set -- "${tmp_args}"
|
||||
|
||||
while true
|
||||
do
|
||||
case "$1" in
|
||||
# Mode switches
|
||||
-a|--all) MODE="ALL"; shift;;
|
||||
-h|--help) MODE="EXIT"; myip_help_print; shift;;
|
||||
-i|--internal) MODE="INTERNAL"; shift;;
|
||||
-V|--version) MODE="EXIT"; myip_version_print; shift;;
|
||||
|
||||
# Global options
|
||||
-T|--test) DRY_RUN="TRUE"; shift;;
|
||||
-v|--verbose) VERBOSE="TRUE"; shift;;
|
||||
|
||||
# End of options
|
||||
--) shift; break;;
|
||||
*) echo "args_parse internal error [$1]!"; exit 1;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Internal IP Get
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
myip_internal_get()
|
||||
{
|
||||
local int_ip
|
||||
local int_label
|
||||
local web_server_ip
|
||||
|
||||
|
||||
if [[ "${VERBOSE}" == "TRUE" ]]
|
||||
then
|
||||
int_label="Internal IP: "
|
||||
else
|
||||
int_label=""
|
||||
fi
|
||||
|
||||
|
||||
dns_lookup "A" "${WEB_SERVER_NAME}" "NOCACHE"
|
||||
web_server_ip="${dns_value}"
|
||||
|
||||
if [[ "${web_server_ip}" == "" ]]
|
||||
then
|
||||
if [[ "${VERBOSE}" == "TRUE" ]]
|
||||
then
|
||||
echo_error "Warning: resolver failed for [${WEB_SERVER_NAME}], using default address: [${WEB_SERVER_IP}]"
|
||||
fi
|
||||
|
||||
web_server_ip="${WEB_SERVER_IP}"
|
||||
fi
|
||||
|
||||
int_ip="$(cmd_exec curl --resolve "${WEB_SERVER_NAME}:80:${web_server_ip}" -s "${WEB_SERVER_URL}" | ip_ip_filter)"
|
||||
|
||||
echo "${int_label}${int_ip}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# External IP Get
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
myip_external_get()
|
||||
{
|
||||
local ext_ip
|
||||
local ext_label
|
||||
local resolver_ip
|
||||
|
||||
|
||||
if [[ "${VERBOSE}" == "TRUE" ]]
|
||||
then
|
||||
ext_label="External IP: "
|
||||
else
|
||||
ext_label=""
|
||||
fi
|
||||
|
||||
dns_lookup "A" "${RESOLVER_NAME}" "NOCACHE"
|
||||
resolver_ip="${dns_value}"
|
||||
|
||||
if [[ "${resolver_ip}" == "" ]]
|
||||
then
|
||||
if [[ "${VERBOSE}" == "TRUE" ]]
|
||||
then
|
||||
echo_error "Warning: resolver failed for [${RESOLVER_NAME}], using default address: [${RESOLVER_IP}]"
|
||||
fi
|
||||
|
||||
resolver_ip="${RESOLVER_IP}"
|
||||
fi
|
||||
|
||||
ext_ip="$(cmd_exec dig +short myip.opendns.com "@${resolver_ip}" | ip_ip_filter)"
|
||||
|
||||
echo "${ext_label}${ext_ip}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# Main
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
myip_args_parse "$@"
|
||||
|
||||
|
||||
|
||||
if [[ "${MODE}" == "EXIT" ]]
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
dns_init
|
||||
|
||||
case "${MODE}" in
|
||||
"INTERNAL")
|
||||
myip_internal_get
|
||||
;;
|
||||
|
||||
"EXTERNAL")
|
||||
myip_external_get
|
||||
;;
|
||||
|
||||
"ALL")
|
||||
myip_internal_get
|
||||
myip_external_get
|
||||
;;
|
||||
|
||||
*)
|
||||
myip_help_print
|
||||
RETVAL=1
|
||||
;;
|
||||
esac
|
||||
|
||||
dns_deinit
|
||||
|
||||
exit ${RETVAL}
|
||||
|
||||
65
etc/bash_completion.d/myip
Normal file
65
etc/bash_completion.d/myip
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# MyIP Bash Completion
|
||||
#
|
||||
# Copyright (C) 2025-2026 Arnaud G. GIBERT
|
||||
# mailto:arnaud@rx3.net
|
||||
#
|
||||
# This is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
# MyIP Completion
|
||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
_myip_completion()
|
||||
{
|
||||
local mode_opts="-h --help -V --version -i --internal -a --all"
|
||||
local glob_opts="-T --test -v --verbose"
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
local mode_set="FALSE"
|
||||
local i
|
||||
|
||||
COMPREPLY=()
|
||||
|
||||
# Scan already provided words to detect if a mode option was given
|
||||
for (( i=1; i<COMP_CWORD; i++ ))
|
||||
do
|
||||
case "${COMP_WORDS[i]}" in
|
||||
-h|--help|-V|--version|-i|--internal|-a|--all)
|
||||
mode_set="TRUE"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Build candidate list depending on whether a mode is already set
|
||||
if [[ "${mode_set}" == "TRUE" ]]
|
||||
then
|
||||
COMPREPLY=( $(compgen -W "${glob_opts}" -- "${cur}") )
|
||||
else
|
||||
COMPREPLY=( $(compgen -W "${mode_opts} ${glob_opts}" -- "${cur}") )
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
|
||||
complete -o filenames -F _myip_completion myip
|
||||
30
www/cgi-bin/myip.cgi
Executable file
30
www/cgi-bin/myip.cgi
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
#
|
||||
# MyIP.CGI
|
||||
#
|
||||
# Copyright (C) 2025-2026 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