View the geographic location of the IP that is logged on to Linux (based on the last command)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.