Changed ipv4 regex to a better version, from https://stackoverflow.com/a/13778973/5853386
Added public ip services to an array for better functionality and maintainability
Added a log to monitor if an ip service is failing
This pull request contains a simple modification to the script to improve compatibility with systems that do not support the \w shorthand in Basic Regular Expressions (BRE). This change ensures consistent behavior across different environments by replacing the \w shorthand with the [A-Za-z0-9_] character range.
Changes Made:
Replaced all instances of \w with the [A-Za-z0-9_] character range.
Reason for the Change:
The \w shorthand, which represents word characters, is not universally supported, notably in the case of FreeBSD. This change ensures portability and maintains a consistent behavior across various systems. This modification will allow the script to function correctly on a wider range of platforms.
Added https:/cloudflare.com/cd-cgi/trace as default ip lookup method.
Removed possibility of MiTM attack through dig. Cleaned script of
unnecessary check for command existance.
Changed the way we generate the api data back to the original. Clarified
comments. Added more logic to how we obtain the public IPv4 address,
such that input is sanitized.
If curl is not found, then the rest of the script can't run so we exit
with an error code. We try to use DNS if HTTPS fails to obtain
a valid IP. Added log messages for these events.
Changed back so that curl is used by default, however dig can be used
as a backup if curl is not installed on the system. Additionally took
my fear of code injection into account by sanitizing the remote input
through a regex.
Used shell built-in command -v to determine if dig is installed and if
it is, use it as default for getting the ip-address. Also made the use
of brackets consistent and updated the the way the data variable is
created before it is sent with curl to make it more readable in the
code.
Permits to run the script on simpler/lighter Linux distributions,
e.g. OpenWRT, where the grep utility available does not permit to use
Perl extended regexp (the `grep -P` option)
Instead of creating a log file. This change leverages the syslog. This allows us to not have to manually rotate logs, or worry about the log file filling up the file system. This also give us timestamps of the logging without having to create the timestamps ourselves. Messages are logged to /var/log/messages by default.