Shell小巧、功能又不失强大,系统管理员必须掌握啊,最近有空就写些小的脚本
这个脚本是使用whois命令查询指定域名的相关信息的,主要是对whois命令输出的整理、格式化输入
代码如下:
- #!/bin/bash
- # Get all domains
- _dom=$@
- # Die if no domains are given
- [ $# -eq 0 ] && { echo "Usage: $0 domain1.com domain2.com ..."; exit 1; }
- for d in $_dom
- do
- _ip=$(host $d | grep 'has add' | head -1 | awk '{ print $4}')
- [ "$_ip" == "" ] && { echo "Error: $d is not valid domain or dns error."; continue; }
- echo "Getting information for domain: $d [ $_ip ]..."
- whois "$_ip" | egrep -w 'OrgName:|City:|Country:|OriginAS:|NetRange:'
- echo ""
- done
使用的时候直接把待查的域名以参数的形式加在程序名后就可以了,如:
- ./script.sh google.com
Getting information for domain: google.com [ 209.85.231.104 ]...
OrgName: Google Inc.
City: Mountain View
Country: US
NetRange: 209.85.128.0 - 209.85.255.255
如果是多个话,也是直接加参数,用空格隔开,如
./script.sh google.com baidu.com topsage.com