linux中中怎么获取局域网的所有机器的IP地址等信息

linux中中怎么获取局域网的所有机器的IP地址等信息,第1张

#!/bin/bash

for i in {2254}

do

ping -c 2 1921681$i

    if [[ $ -eq 0 ]]

    then

        echo IP addr 1921681$i ok

        echo 1921681$i >> /tmp/ok_ip

      else

          echo IP addr 1921681$i bad

          echo 1921681$i >> /tmp/bad_ip

    fi

done

以上脚本只是查找 网段为19216810/24的已用ip,并显示,将已用ip 转存到 /tmp/ok_ip,

将空闲ip显示,并转存到 /tmp/bad_ip中。

#!/bin/bash

################################变量定义################################

nameDevice=eth0

ipAdddress=1921684110

prefix=2552552550

netMask=2552552550

gateway=19216841

dns1=8888

dns2=19216840

################################函数模块################################

##设置NetworkManager服务

function SetNetworkManagerDisable(){

  systemctl stop NetworkManager && systemctl disable NetworkManager && echo "NetworkManager is stop and disable" && return 0 || return 1

}

##设置NetworkManager服务

function SetNetworkEnable(){

  systemctl restart network && systemctl enable network && echo "network is start and enable" && return 0 || return 1

}

##查看服务器第一个网卡名称

function FindFirstNICName(){

  ifconfig|head -n 1|cut -d \: -f 1 && [ $ == 0 ] && nameDevice=`ifconfig|head -n 1|cut -d \: -f 1` && return 0 || return 1

}

##设置服务器网卡IP地址

function SetNICFile(){

  cat > /etc/sysconfig/network-scripts/ifcfg-$nameDevice <<EOF

TYPE="Ethernet"

BOOTPROTO="none"

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

NAME=$nameDevice

DEVICE=$nameDevice

ONBOOT=yes

IPADDR=$ipAdddress

PREFIX=$prefix

NETMASK=$netMask

GATEWAY=$gateway

DNS1=$dns1

DNS2=$dns2

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

IPV6_PRIVACY=no

EOF

}

##消除变量

function UnsetVariate(){

  unset nameDevice

  unset ipAdddress

  unset prefix

  unset netMask

  unset gateway

  unset dns1

  unset dns2

}

################################程序流程################################

##设置网络服务为network

FindFirstNICName

SetNICFile

SetNetworkEnable

SetNetworkManagerDisable

UnsetVariate

你用了重定向,把IP写到文件a 里面,而不是变量a。

route add default gw $( LC_ALL ifconfig|grep ‘inet addr’|grep -v '127001'|cut -d: -f2 |awk ' print $1' ) 大概是这样。 你的命令能不能正确获得IP 我不知道。

你编辑的是ifcfg-eth2,怎么写进去的Device是eth0??

我是65的测试系统,执行之后可以正常启动,不过报错是针对/etc/initd/network这个脚本的

/IP_eth0sh 104

/etc/initd/network: line 184: command not found

/etc/initd/network: line 184: 33mDEVICE=eth0: command not found

/etc/initd/network: line 185: command not found

/etc/initd/network: line 185: 33mTYPE=Ethernet: command not found

/etc/initd/network: line 184: command not found

/etc/initd/network: line 184: 33mDEVICE=eth1: command not found

/etc/initd/network: line 185: command not found

/etc/initd/network: line 185: 33mTYPE=Ethernet: command not found

/etc/initd/network: line 184: command not found

/etc/initd/network: line 184: 33mDEVICE=eth2: command not found

/etc/initd/network: line 185: command not found

/etc/initd/network: line 185: 33mTYPE=Ethernet: command not found

#!/bin/bash

find_ip=$(sed -nr 's/eth0ip="()"/\1/p' ipxml)

echo $find_ip

以上就是关于linux中中怎么获取局域网的所有机器的IP地址等信息全部的内容,包括:linux中中怎么获取局域网的所有机器的IP地址等信息、Linux shell脚本编程——IP地址设置、shell 获取ip地址 然后使用这个ip更改默认路由等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9509942.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存