Linux使用shell编程自动切换IP
来源:互联网 发布:sip服务器端口 编辑:程序博客网 时间:2024/05/17 03:24
Ubuntu系统,由于上下班使用的IP不一样,每次手工修改很麻烦。
今天参考网络资料,做成了批处理。
全文如下:
#!/bin/bash
#上下班自动切换网络地址
#上班IP,Mac,网关
IP[0]=192.168.0.2
MAC[0]=00:01:02:03:04:05
GW[0]=192.168.0.1
#下班IP,Mac,网关
IP[1]=192.168.1.3
MAC[1]=00:02:03:04:05:06
GW[1]=192.168.1.1
#设定下班时间
off=1630
now=$(date +%H%M)
let now=${now/0/$null}
let int=$now-$off
#echo $now-$off=$int
#这里可能需要进一步取整
let id=$now/$off
#echo $id
ifconfig eth0 down
ifconfig eth0 hw ether "${MAC[$id]}"
ifconfig eth0 up
#Ubuntu上无network服务?
#service network stop
ifconfig eth0 "${IP[$id]}" netmask 255.255.255.0
route add -net default gw "${GW[$id]}"
#service network start
sleep 1
echo "Network Connected."
复制后保存为【ip.sh】,运行terminal进入保存目录,执行【./ip.sh】即可。
当然你也可以将其添加到启动程序中,这样每次开机就自动修改了。
<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- Linux使用shell编程自动切换IP
- Linux使用shell编程自动切换IP
- XP下 使用脚本,自动切换IP
- linux 自动ping ip的shell脚本
- shell-自动更改LINUX服务器IP
- shell编程之sudo实现权限自动切换
- linux--tomcat自动重启--shell编程
- Linux shell 编程简单使用
- 多网口编程,IP切换
- Linux网络编程----bind自动获取自己的IP和PORT,端口使用的注意事项
- 使用iptables自动封IP的Shell脚本
- linux使用dhclient自动获取IP
- 如何使用Linux命令 自动获取IP
- 自动切换ip方案批处理文件
- 自动切换ip地址批处理
- 自动切换网络IP 配置
- Linux中shell自动交互的使用
- linux查看当前使用的shell,修改shell,shell编程?
- 一天的活动
- Flex4的Application中设置背景图像
- 第九周上机任务(一)
- linux计划任务
- storm版本
- Linux使用shell编程自动切换IP
- Chrome 获取屏幕位置问题
- JQuery插件实现相册效果(数据库调用图片)
- 字节大小端判断
- POJ 2195 Going Home
- linux下常用函数及命令
- Linux Shell中的美元符号$
- Zend Studio 9.0.1 修改默认字体\颜色的修改(字体及方法名等)
- 一款无损wav格式换肤播放器