22073 days on xHamster
53646M profile views
14794K subscribers
13594 comments left

Validating an ip address in a bash script

Revise config file." ;; "badauth") LOGTEXT="(badauth) Invalid username password combination." ;; "badagent") LOGTEXT="(badagent) Client disabled - No-IP is no longer allowing requests from this update script." ;; "! donator) An update request was sent including a feature that is not available." ;; "abuse") LOGTEXT="(abuse) Username is blocked due to abuse." ;; "911") LOGTEXT="(911) A fatal error on our side such as a database outage.

HELP: validating IP addresses any way possible -------------------------------------------------------------------------------- I am trying to validate input from the user in a script. I therefore wrote myself a small bash-script for a reliable and fast update of the IP-address.The script is certainly not perfect, but it has been working reliably for months now. /bin/bash # ------------------------------------------------------- # CONFIG # ------------------------------------------------------- USERNAME="dein-noip-benutzername" PASSWORD="dein-noip-passwort" HOST="net" LOGFILE=/var/log/IPFILE=/tmp/current_ip USERAGENT="Datenreise NOIP Updater/0.4" if [ ! -ne 0 ]; then LOGTEXT="IP file could not be created." LOGDATE="[$(date '%d.%m.%Y %H:%M:%S')]" echo "$LOGDATE $LOGTEXT" $LOGFILE exit 1 fi # IP Validator # function validate_ip() GET_IP_URLS=( " "" " " ) for key in $; do NEWIP=$(curl -s $ | grep -o '[0-9]\.[0-9]\.[0-9]\.[0-9]\') if validate_ip $NEWIP; then break elif [ $key -eq $(($ - 1)) ]; then LOGTEXT="Could not find current IP. " LOGDATE="[$(date '%d.%m.%Y %H:%M:%S')]" echo "$LOGDATE $LOGTEXT" $LOGFILE fi done STOREDIP=$(cat $IPFILE) if [ "$NEWIP" !I know that the man page is the best place for the nitty gritties I was just looking for something that maybe got more into examples of how to pull it off in the phylosophy or had more examples. - Andrew Jackson UIN=66618055 wrote ^^^^^ Oh man, I had to look closely, this is very cool!An absolute perfect example of using bash's "local" builtin command!

-- Jeremy | [email protected] does this shell function, without using any external command: is_ip() if is_ip $addr then echo "OK" else echo "BAD" fi -- Chris F. Johnson [email protected]================================================================= [email protected] That is some butifull code.

Please or register to post comments
If spammers comment on your content, only you can see and manage such comments Delete all

Validating an ip address in a bash script introduction

Validating an ip address in a bash script

Recent posts

03-Aug-2018 04:56
03-Aug-2018 10:52
03-Aug-2018 16:50
03-Aug-2018 23:28