SHELL脚本中取得域名的IP地址
2021/8/13 7:06:29
本文主要是介绍SHELL脚本中取得域名的IP地址,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
单个获取
编写角本pingip.sh
#!/bin/sh ADDR=qq.com TMPSTR=`ping ${ADDR} -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'` echo ${TMPSTR} echo ${TMPSTR} >> 666.txt
执行结果
haima@haima-PC:~/Desktop$ sh pingip.sh 58.250.137.36
批量获取
思路:
从文件里循环读取每行域名,然后获取,输出到文件里
新建domain_list.txt
文件
qq.com baidu.cn
留言个空行,否则读到最后一行域名
编写角本代码pingip_batch.sh
#!/bin/bash filename=domain_list.txt # 要读取的文件 proc_cnt=0 # 计数器 cat $filename | while read LINE # 循环读取 do echo "" proc_cnt=`expr $proc_cnt + 1` echo "processing $proc_cnt $LINE" dumpstring=`ping ${LINE} -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'` echo "" echo $dumpstring echo $dumpstring >> domain_list-resp.txt sleep 0.05 done
执行
haima@haima-PC:~/Desktop/获取ip$ sh pingip_batch.sh processing 1 qq.com 58.250.137.36 processing 2 baidu.cn 220.181.38.148
输出文件:
这篇关于SHELL脚本中取得域名的IP地址的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28AI给的和自己写的Python代码,都无法改变输入框的内容,替换也不行
- 2024-09-27Sentinel配置限流资料:新手入门教程
- 2024-09-27Sentinel配置限流资料详解
- 2024-09-27Sentinel限流资料:新手入门教程
- 2024-09-26Sentinel限流资料入门详解
- 2024-09-26Springboot框架资料:初学者入门教程
- 2024-09-26Springboot框架资料详解:新手入门教程
- 2024-09-26Springboot企业级开发资料:新手入门指南
- 2024-09-26SpringBoot企业级开发资料新手指南
- 2024-09-26Springboot微服务资料入门教程