Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4826329
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类:

2009-01-07 22:01:06

也算是我自己的学以致用系列之一吧^_^

ubuntu:

#!/bin/bash
PS3="Select your network:"
echo "auto eth0" > /etc/network/interfaces
select choice in "home(dhcp)" "company(static)"
  do
    case "$REPLY" in
    1)
      echo "iface eth0 inet dhcp" >> /etc/network/interfaces
      break;;
    2)
      echo "iface eth0 inet static" >> /etc/network/interfaces
      echo "address 192.168.10.160" >> /etc/network/interfaces
      echo "netmask 255.255.255.0" >> /etc/network/interfaces
      echo "gateway 192.168.10.2" >> /etc/network/interfaces
      break;;
    *)
      echo -e "$REPLY is not a valid choice.Try again\n" 1>&2
      REPLY=
      ;;
    esac
  done
echo "auto lo" >> /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces
/etc/init.d/networking restart


redhat,fedora,centos的:

#!/bin/bash
echo 'DEVICE=eth0' > /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'ONBOOT=yes' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'TYPE=Ethernet' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'BOOTPROTO=static' >> /etc/sysconfig/network-scripts/ifcfg-eth0
if [ $1 = "home" ] ; then
echo 'IPADDR=192.168.10.160' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'NETMASK=255.255.255.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'GATEWAY=192.168.10.2' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'nameserver 202.96.69.38' > /etc/resolv.conf
else
echo 'IPADDR=10.0.0.2' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'NETMASK=255.0.0.0' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'GATEWAY=10.0.0.1' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo 'nameserver 10.0.0.100' > /etc/resolv.conf
fi;
service network restart


 


windows的

@echo off
color 1f
title 网络环境切换管理
echo.
echo *** 设置IP参数,设置IE代理 ***
echo.
echo.
goto menus~

:menus~
echo.
echo 请选择:
echo 1 切换到公司网
echo 2 切换到自动获取直接上网
echo.
set /p select=请输入菜单对应数字后回车:
if /i "%select%" == "1" goto neusoft
if /i "%select%" == "2" goto auto
goto menus~

:neusoft
cls
netsh interface ip reset "本地连接"
echo 设置IP...
netsh interface ip add address "本地连接" 192.168.10.160 255.255.255.0
echo 设置网关...
netsh interface ip add address "本地连接" gateway=192.168.10.2 gwmetric=1
echo 设置DNS...
netsh interface ip set dns "本地连接" static 202.103.24.68 primary
del 本地连接
echo 设置IE代理...
@echo Windows Registry Editor Version 5.00>>r.reg
@echo [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings]>>r.reg
@echo "ProxyEnable"=dword:00000001>>r.reg
regedit /s r.reg
del r.reg
goto exit



:auto
cls
echo 设置IP...
netsh interface ip set address name="本地连接" source=dhcp
echo 设置DNS...
netsh interface ip set dns name="本地连接" source=dhcp
@echo Windows Registry Editor Version 5.00>>r.reg
@echo [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings]>>r.reg
@echo "ProxyEnable"=dword:00000000>>r.reg
regedit /s r.reg
del r.reg
goto exit



:exit
cls
echo.
echo.
echo.
echo.
echo.
echo 恭喜!已完成所有设置.
echo.
echo.
echo.
echo.
echo.
echo.
pause
exit

阅读(1960) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~