linux获取网络信息
2012-02-08 12:08
148 查看
在linux的网络编程中,经常需要用到网络信息如:ip、gateway、dns等。以下脚本实现了获取网络信息的功能,包括ip、broadcast、netmask、gateway以及dns的信息
default_route=$(ip route show) default_interface=$(echo $default_route | sed -e 's/^.*dev \([^ ]*\).*$/\1/' | head -n 1) address=$(ip addr show label $default_interface scope global | awk '$1 == "inet" { print $2,$4}') #ip address ip=$(echo $address | awk '{print $1 }') ip=${ip%%/*} #broadcast broadcast=$(echo $address | awk '{print $2 }') #mask address mask=$(route -n |grep 'U[ \t]' | head -n 1 | awk '{print $3}') #gateway address gateway=$(route -n | grep 'UG[ \t]' | awk '{print $2}') #dns dns=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}') echo ip:$ip,mask:$mask,broadcast:$broadcast,gateway:$gateway,dns:$dns
相关文章推荐
- linux获取网络信息函数
- 用ioctl获取无线网络信息 /usr//include/linux/wireless.h
- 转载:linux系统下 python获取 内存、cpu、负载、网络流量、硬盘等信息
- Linux下通过ioctl系统调用来获取和设置网络信息
- Linux下通过ioctl系统调用来获取和设置网络信息
- Linux中获取网络信息的netstat命令的常用参数和用法
- Linux下通过ioctl系统调用来获取和设置网络信息
- linux 获取本地网络信息 -ip,mac ,等
- linux C获取网络信息
- Linux下通过ioctl系统调用来获取和设置网络信息
- linux系统下 python获取 内存、cpu、负载、网络流量、硬盘等信息
- Linux网络编程之"获取网络天气信息"
- linux 系统获取网络ip, mask, gateway, dns信息小程序
- Linux下通过ioctl系统调用来获取和设置网络信息
- Linux编程获取网络信息总结
- Linux中获取本机网络信息的几个函数及应用
- Linux 网络编程基础(2)-- 获取主机信息
- linux 系统获取网络ip, mask, gateway, dns信息小程序
- linux编程获取网络信息
- Linux 网络编程之通过IP或者主机名获取信息