ipAllocate_and_linkState_hacking
#!/bin/bash
# Author: Joshua Chen
# Date: Jun
# Location: Shenzhen #. 解读这两个程序是因为程序中包含了大部分shell脚本的基本语法;
#. 省去以后需要使用到shell脚本的时候,需要参考的需求;
#. 在本代码中,以24位掩码为基准,如果IP为: 10.1.1.7,那么前面三位数是网络位: 10.1.,最后一位是主机位:
# -- 晴 深圳 曾剑锋 # Description: allocate IPs to students #每个人分配一个主IP, 3个辅助IP
EXTRA_COUNT=
#IP的前缀,相当这个脚本用于分配10..1段的IP,也就是网络位
IP_PREFIX=10.1.
#最多分配50个主IP
MAX_GRP=
#主IP的主机位从11开始
PRIM_MIN=
#主IP的主机位最大值
PRIM_MAX=$((PRIM_MIN + MAX_GRP -))
#扩展IP的主机位最小值
EXTRA_MIN=$((PRIM_MAX + ))
#扩展IP的主机位最大值
#EXTRA_MAX=$((EXTRA_MIN + MAX_GRP * EXTRA_COUNT -)) #获取传入的第一个参数,如果文件不存在,那个就退出,
#并且打印出命令的使用方法.
list=$
if [ ! -e "$list" ];then
#输出到标准错误输出
echo "Can not locate list file '$list'" >&
#需要传入有学生姓名的文件,每个学生名字占一行
echo "Usage: $(basename $0) <name list>"
exit
fi #检查list路径下文件的行数是否大于MAX_GRP,以下提供2种写法
#if [ $(wc -l "$list" | cut -d " " -f1) -gt "$MAX_GRP" ];then
if [ $(wc -l < "$list") -gt "$MAX_GRP" ];then
echo "Too many entries in the name list! maximum $MAX_GRP is allowed" >&
exit
fi #分配主IP
#每次从list代表的文件中读取一行名字,保存在name的变量中,
#然后是用printf组合分配IP.
echo "------- Primary IP -------"
n=$PRIM_MIN
while read name
do
printf "%s.%-3s %s\n" "${IP_PREFIX}" $n "$name"
((n++)) #语法要求,这样就可以像写C一样
done < "$list" #分配辅助IP
#因为辅助IP这里需要分配3个,所以while里面再是用for循环
#对IP进行分配.
echo
echo "------- Extra IP -------"
n=$EXTRA_MIN
while read name
do
for i in $(seq $EXTRA_COUNT) #seq用于产生序列供for循环使用
do
printf "%s.%-3s %s\n" "${IP_PREFIX}" $n "$name"
((n++))
done
done < "$list" #退出程序
exit # Description: detect the ethernet link state #网卡设备所在的目录
dir=/sys/class/net
#文件名carrier
file=carrier # need root privilege
if [ "$UID" -ne ]; then
echo "Must be root"
exit
fi if [ ! -d $dir ];then
echo "Directory $dir doesn't exist, quit."
exit
fi cd $dir # do we have an NIC? #Network Interface Card
if ! ls | grep -q ^eth; then
echo "No NIC detected"
exit
fi # check the status of each NIC
ls | grep ^eth | while read dev
do
# take it up first
ifconfig $dev up &> /dev/null # if the file is not found and put error to /dev/null
if [ "$(cat $dev/$file 2>/dev/null)" = "" ];then
echo "$dev: link ok"
else
echo "$dev: no link"
fi
done exit
ipAllocate_and_linkState_hacking的更多相关文章
随机推荐
- HDU2017新生赛 找方块
思路: 先n^3预处理出每个点能到达的(1010串)最上面的行下标. 然后再n^3暴力一下,对于每个点,往左走看能走到哪,边走边更新面积. 代码: #include<bits/stdc++.h& ...
- xinwenti
angularjs angular2脏检查机制和数据双向绑定远离 angular2 aot编译
- vs2010打包安装
[WinForm] VS2010发布.打包安装程序(超全超详细) 2017年02月17日 21:47:09 y13156556538 阅读数:16487更多 个人分类: C#winform 1. ...
- Python基础--数据类型
一.数据类型是什么鬼? 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同 ...
- hdu 2266 dfs+1258
How Many Equations Can You Find Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- CoderForce 180D-Name (构造+回溯)
题目大意:给两个字符串s,t,用s中的字符重新组合构造出按字典序最小的但比t大的新字符串. 题目分析:先统计s中各个字母出现的次数,然后从t的左端向右端依次构造出新串的每一位上的字母.这个过程我是用回 ...
- CentOS搭建“加速器”
1.安装Shadowsocks 服务端 yum -y update yum install -y python-setuptools && easy_install pip pip i ...
- 《程序员面试金典》习题解答(C/C++)
一.数据结构 1.数组与字符串 1.1 实现一个算法,确定一个字符串的所有字符是否全都不同.假使不允许使用额外的数据结构,又该如何处理? /* 假设字符集为ASCII字符串,那么字符串至多有256个 ...
- httpclient 相关使用介绍
httpclient中sessionId的获取与设置 public class HttpSessionId { public static void main(String[] args) throw ...
- 合法的MAC地址
以太网的地址为48位,由ieee统一分配给网卡制造商,每个网卡的地址都必须是全球唯一的.共6个字节的长度 字节 5 4 3 2 1 0 位 47..40 39..32 31..24 23..16 1 ...