Scripting Features: View the physical location of the IP address of the logged-on system
Execution mode: Bash login_city_info_use_taobaoapi.sh username
[Email protected] storage]$ bash login_city_info_use_taobaoapi.sh root "IP": "119.4.254.195" "Country": "China" "Region": " Sichuan "City": "Chengdu" "ISP": "Unicom" "IP": "182.149.160.103" "Country": "China" "region": "Sichuan" "City": "Chengdu" "ISP": "Telecommunications" "IP": " 222.209.8.224 "Country": "China" "region": "Sichuan" "City": "Chengdu" "ISP": "Telecommunications" "IP": "222.209.8.70" "Country": "China" "region": "Sichuan" " City ":" "Chengdu" "ISP": "Telecommunications" "IP": "222.209.9.13" "Country": "China" "region": "Sichuan" "City": "Chengdu" "ISP": "Telecom" "IP": "223.85.209.56" " Country ":" China "" region ":" Sichuan "" City ":" Chengdu "" ISP ":" Mobile "[[email protected] storage]$
The script reads as follows:
[Email protected] storage]$ more login_city_info_use_taobaoapi.sh #!/bin/bashif [-z] $ "];thenecho" Usage:bash Login_c ity_info_use_taobaoapi.sh root "Exit 1fiip_addr_list= ' last | grep $ | awk ' {print $} ' | Sort | Uniq ' for ip_addr in ${ip_addr_list}doresult= ' curl-s http://ip.taobao.com/service/getipinfo.php?ip=${ip_addr} ' Result_code= ' echo ${result} | Awk-f ', ' {print $} ' | Awk-f ': ' {print $} ' result_info= ' echo ${result} | Awk-f ': {' {' {print $} ' | awk-f ', ' {print $1,$2,$4,$5,$7} ' if [' ${result_code} '! = ' 0 '];thenecho-e ' \e[1;32mip:\e[0m$ {ip_addr} \e[1;32merror\e[0m try Again! "Elseecho ${result_info}fidone
View the location of the IP that is logged on to Linux (based on the last command)