查看登录过Linux的IP的地理位置(基于last命令)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查看登录过Linux的IP的地理位置(基于last命令)相关的知识,希望对你有一定的参考价值。
脚本功能:查看登录过系统的IP地址的物理位置
执行方式: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":"中国" "region":"四川" "city":"成都" "isp":"联通" "ip":"182.149.160.103" "country":"中国" "region":"四川" "city":"成都" "isp":"电信" "ip":"222.209.8.224" "country":"中国" "region":"四川" "city":"成都" "isp":"电信" "ip":"222.209.8.70" "country":"中国" "region":"四川" "city":"成都" "isp":"电信" "ip":"222.209.9.13" "country":"中国" "region":"四川" "city":"成都" "isp":"电信" "ip":"223.85.209.56" "country":"中国" "region":"四川" "city":"成都" "isp":"移动" [[email protected] Storage]$
脚本内容如下:
[[email protected] Storage]$ more login_city_info_use_taobaoAPI.sh #!/bin/bash if [ -z "$1" ];then echo "Usage: bash login_city_info_use_taobaoAPI.sh root" exit 1 fi ip_addr_list=`last | grep $1 | awk '{print $3}' | sort | uniq ` for ip_addr in ${ip_addr_list} do result=`curl -s http://ip.taobao.com/service/getIpInfo.php?ip=${ip_addr}` result_code=`echo ${result} | awk -F',' '{print $1}' | awk -F':' '{print $2}'` result_info=`echo ${result} | awk -F':{' '{print $2}' | awk -F',' '{print $1,$2,$4,$5,$7}'` if [ "${result_code}" != "0" ];then echo -e "\e[1;32mIP:\e[0m${ip_addr} \e[1;32mERROR\e[0m please try again! " else echo ${result_info} fi done
以上是关于查看登录过Linux的IP的地理位置(基于last命令)的主要内容,如果未能解决你的问题,请参考以下文章
Windows服务器远程登录日志查询方法,linux查看登录日志方法