Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use shell and python to determine whether an IP is on the whitelist or not

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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 ()

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report