In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of Linux shell how to judge the legitimacy of IP, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this Linux shell article on how to judge the legitimacy of IP. Let's take a look.
Idea: IP consists of four digits, divided by dots, and each field cannot be greater than 255. it must conform to this format.
Method 1: function check_ip () {IP=$1 VALID_CHECK=$ (echo $IP) awk-F. '$1) if echo $IP | grep-E "^ [0-9] {1 VALID_CHECK:-no 3}\. [0-9] {1 IP 3}\. [0-9] {1 3}\. [0-9] {1 VALID_CHECK:-no 3} $" > / dev/null; then if [${VALID_CHECK:-no} = "yes"]; then echo "IP $IP available." Else echo "IP $IP not available!" Fi else echo "IP format error!" Fi} # Example check_ip 192.168.1.1 check_ip 256.1.1.1 method 2 function check_ip () {IP=$1 if [[$IP= ~ ^ [0-9] {1 3}\. [0-9] {1 3}\. [0-9] {1Mague 3}\. [0-9] {1jue 3} $]; then FIELD1=$ (echo $IP | cut-d. -F1) FIELD2=$ (echo $IP | cut-d. -f2) FIELD3=$ (echo $IP | cut-d. -f3) FIELD4=$ (echo $IP | cut-d. -f4) if [$FIELD1-le 255-a $FIELD2-le 255-a $FIELD3-le 255-a $FIELD4-le 255]; then echo "IP $IP available." Else echo "IP $IP not available!" Fi else echo "IP format error!" Fi} # Example check_ip 192.168.1.1 check_ip 256.1.1.1 add a loop and re-enter it if it is wrong until it is correct: #! / bin/bash function check_ip () {local IP=$1 VALID_CHECK=$ (echo $IP | awk-F. '$1) if echo $IP | grep-E "^ [0-9] {1 IP 3}\. [0-9] {1 IP 3}\. [0-9] {1 recorder 3}\. [0-9] {1 VALID_CHECK 3} $" > / dev/null; then if [$VALID_CHECK = "yes"]; then echo "IP $IP available!" Return 0 else echo "IP $IP not available!" Return 1 fi else echo "IP format error!" Return 1 fi} while true; do read-p "Please enter IP:" IP check_ip $IP [$?-eq 0] & & break done's article on "how Linux shell judges the legitimacy of IP" ends here. Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to judge the legality of IP by Linux shell". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.