Use shell and python to determine whether an IP is on the whitelist or not
1 、 The shell script is as follows: [root@mysql01 ~] # cat a.shrunk whitelist # white_list= (192.168.20.2 192.168.20.3 192.168.20.4 192.168.20.5) # # define script usage # function USAGE () {echo-e "\ 033 [33m $0] is:-I: specify the ip address to be judged\ 033 [0m"} # determine the script passing parameters and assign variables # # if [[$#-eq 0]] | | [$1 = ='- h']] | | [$1 = ='--help']] Then USAGE exit 0fiwhile getopts ": I:" optname;do case "$optname" in "I") ip=$OPTARG;; *) echo "this option has no value!" USAGE exit 1;; esacdone # determines whether IP exists in the whitelist # if [[${white_list [@]} = ~ $ip]] The then echo "$ip is in whitelist." else echo "$ip is not in whitelist." fi2 and python scripts (python version 3.8) are as follows:''to determine whether an IP has a whitelist. Define the whitelist white_list = {'192.168.20.2,' 192.168.20.3, '192.168.20.4,' 192.168.20.5'} # 2. Receive the IP to be judged and make the judgment def main (): ip = input ('Please enter the IP address to be judged:') if ip in white_list: print (ip +'in the whitelist!') Else: print (ip + "not on the whitelist") # 3. Program entry if _ _ name__ = ='_ _ main__': main ()