- #!/bin/bash
- hostname
- ip=`/sbin/ifconfig eth0|grep "inet addr:"|sed 's/Bcast.*$//'g |awk -F ":" {'print $2'}`
- dns=`cat /etc/resolv.conf |grep -v '#'|sed 's/nameserver//'`
- for i in $ip
- do
- echo "$i"
- done
- for a in $dns
- do
- echo "$a"
- done
0
本帖最后由 wsw13640218682 于 2016-2-21 23:50 编辑
#!/bin/bash
h=`awk -F= '/HOSTNAME/{print $NF}' /etc/sysconfig/network`
ip=`ifconfig eth0 | awk -F: '/inet addr/{print $2}' |awk '{print $1}'`
dns1=`cat /etc/resolv.conf | awk '/202.96.128.86/{print $2}'`
dns2=`cat /etc/resolv.conf | awk '/202.96.128.166/{print $2}'`
for a in $h
do
echo "localhost: $a"
done
for b in $ip
do
echo "localip: $b"
done
for c in $dns1 $dns2
do
echo -e "localdns1: $c\nlocaldns2: $c"
done
#!/bin/bash
h=`awk -F= '/HOSTNAME/{print $NF}' /etc/sysconfig/network`
ip=`ifconfig eth0 | awk -F: '/inet addr/{print $2}' |awk '{print $1}'`
dns1=`cat /etc/resolv.conf | awk '/202.96.128.86/{print $2}'`
dns2=`cat /etc/resolv.conf | awk '/202.96.128.166/{print $2}'`
for a in $h
do
echo "localhost: $a"
done
for b in $ip
do
echo "localip: $b"
done
for c in $dns1 $dns2
do
echo -e "localdns1: $c\nlocaldns2: $c"
done
0
你写的这个不通用,出了广东就查不到DNS
{:4_91:}
wsw13640218682 发表于 2016-2-21 23:31
#!/bin/bash
h=`awk -F= '/HOSTNAME/{print $NF}' /etc/sysconfig/network`
ip=`ifconfig eth0 | awk -F ...
你写的这个不通用,出了广东就查不到DNS
{:4_91:}
0
- #!/bin/bash
- ##written by wangyl
- ##2016-4-19
- ip(){
- a=`ifconfig $n | awk '{print $2}' | awk 'NR==2' | awk -F':' '{print $2}'`
- echo "您的ip地址为:" "$a"
- }
- read -p "请输入您的网卡:" n
- ip
- b=`hostname`
- echo "您的主机名为:" "$b"
- for i in `cat /etc/resolv.conf | grep "nameserver" | awk '{print $2}'`;
- do
- echo "您的dns地址为:" "$i"
- done
0
本帖最后由 dessler 于 2016-4-22 01:23 编辑
我给每个都加了翻译,但是我的输出有空格不知道怎么回事
- #!/bin/bash
- hostname
- #获取主机名
- ip=`/sbin/ifconfig eth0 | grep "inet addr:"|sed 's/Bcast.*$//'g | awk -F ":" {'print $2'}`
- #定义变量
- #ficonfig 获取ip地址信息
- #grep 截取有显示ip的行
- #sed 替换 掩码及网关为空
- #asw 定义分割符号打印二列
- dns=`cat /etc/resolv.conf |sed 's/nameserver//'`
- #定义变量
- #cat 查看dns
- #sed 替换字母为空
- echo -e "$ip\n$dns"
- #打印 变量ip 和变量dns
我给每个都加了翻译,但是我的输出有空格不知道怎么回事
编辑回复