自动切换网络访问脚本(不完全版)
来源:互联网 发布:淘宝达人手机发帖 编辑:程序博客网 时间:2024/06/12 01:21
'*****************************************************************
' 自动切换网络访问脚本(不完全版)
' Created By Cheery Ke, All Reserved
' Version 0.9.0
' 2005.5.26 02:40
'*****************************************************************
'*****************************************************************
'
' 注意:
' 1:本脚本文件应通过组策略设置为登录脚本;
' 2:存放ipmap.xml的远程服务器应位于内网ip可访问的位置;
' 3:通过组策路设置注销脚本为i.cmd,以便每次重新登录后远程服务器均可被访问;
' 4:可于用户桌面上创建两个快捷方式,分别指向i.cmd以及o.cmd,用以切换内外网的访问;
' 5:本脚本尚未完善。
'
'*****************************************************************
'本方法用于从远程加载本机IP记录
Sub LoadIpMap
Dim xmlDoc
Set xmlDoc = CreateObject( "Microsoft.XMLDOM")
xmlDoc.async = False
Dim xNode
Dim currentNodeContent
'从指定的远程服务器加载ipmap.xml文件 ipmap.xml文件示例见本文末尾
If xmlDoc.Load("http://localhost/ipmap.xml") Then
Set objNodeList = xmlDoc.getElementsByTagName("machine")
For index = 0 to objNodeList.length - 1
'根据MAC判断是否为本机记录 本机MAC可通过解析IPCONFIG -ALL命令结果得到
If objNodeList.item(index).getAttribute("mac") = "aa" Then
'调用CreateCMDI 创建访问内网的i.cmd文件
CreateCMDI objNodeList.item(index).getAttribute("iip") , objNodeList.item(index).getAttribute("igw") , objNodeList.item(index).getAttribute("isnm")
'调用CreateCMDO 创建访问外网的o.cmd文件
CreateCMDO objNodeList.item(index).getAttribute("oip") , objNodeList.item(index).getAttribute("ogw") , objNodeList.item(index).getAttribute("osnm")
'退出循环
Exit For
End If
Next
End If
End Sub
'本方法用于创建访问内网的i.cmd文件
'本方法可与下一个方法合并为一个 懒得改了~~
Sub CreateCMDI( iip , igw , isnm )
Dim fso, f1
'创建FileSystemObject的调用
Set fso = CreateObject("Scripting.FileSystemObject")
'创建文本文件 地址可更改为%WinDir%/System32下
Set f1 = fso.CreateTextFile("c:/i.cmd", True)
f1.WriteLine "@echo off"
If igw = "" Then
'本地连接 应为变量 通过命令行应可解析得到 有待尝试
f1.WriteLine "netsh interface ip set address 本地连接 static " & iip & " " & isnm & " > nul"
Else
f1.WriteLine "netsh interface ip set address 本地连接 static " & iip & " " & isnm & " " & igm & " 1 > nul"
End If
f1.write "exit"
f1.close
End Sub
'本方法用于创建访问外网的o.cmd文件
Sub CreateCMDO( iip , igw , isnm )
Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:/o.cmd", True)
f1.WriteLine "@echo off"
If igw = "" Then
f1.WriteLine "netsh interface ip set address 本地连接 static " & iip & " " & isnm & " > nul"
Else
f1.WriteLine "netsh interface ip set address 本地连接 static " & iip & " " & isnm & " " & igm & " 1 > nul"
End If
f1.write "exit"
f1.close
End Sub
Call LoadIpMap
'*****************************************************************
'
'IPMAP.xml 文件示例
'
'<root>
' <!--
' 每一个machine节点为一台机器 其中
' mac指mac地址 ip为IP地址 gw为网关 snm为子网掩码
' 前缀i表示内网 o表示外网
'
' 如果机器数量较多 本文件可采用ARP命令辅助 自动生成
' -->
' <machine
' mac="00-05-5D-86-59-00"
' iip="192.168.0.112"
' igw="192.168.0.1"
' isnm="255.255.255.0"
' oip="10.62.1.189"
' ogw="10.62.1.1"
' osnm="255.255.0.0"
' />
'</root>
'
'*****************************************************************
' 自动切换网络访问脚本(不完全版)
' Created By Cheery Ke, All Reserved
' Version 0.9.0
' 2005.5.26 02:40
'*****************************************************************
'*****************************************************************
'
' 注意:
' 1:本脚本文件应通过组策略设置为登录脚本;
' 2:存放ipmap.xml的远程服务器应位于内网ip可访问的位置;
' 3:通过组策路设置注销脚本为i.cmd,以便每次重新登录后远程服务器均可被访问;
' 4:可于用户桌面上创建两个快捷方式,分别指向i.cmd以及o.cmd,用以切换内外网的访问;
' 5:本脚本尚未完善。
'
'*****************************************************************
'本方法用于从远程加载本机IP记录
Sub LoadIpMap
Dim xmlDoc
Set xmlDoc = CreateObject( "Microsoft.XMLDOM")
xmlDoc.async = False
Dim xNode
Dim currentNodeContent
'从指定的远程服务器加载ipmap.xml文件 ipmap.xml文件示例见本文末尾
If xmlDoc.Load("http://localhost/ipmap.xml") Then
Set objNodeList = xmlDoc.getElementsByTagName("machine")
For index = 0 to objNodeList.length - 1
'根据MAC判断是否为本机记录 本机MAC可通过解析IPCONFIG -ALL命令结果得到
If objNodeList.item(index).getAttribute("mac") = "aa" Then
'调用CreateCMDI 创建访问内网的i.cmd文件
CreateCMDI objNodeList.item(index).getAttribute("iip") , objNodeList.item(index).getAttribute("igw") , objNodeList.item(index).getAttribute("isnm")
'调用CreateCMDO 创建访问外网的o.cmd文件
CreateCMDO objNodeList.item(index).getAttribute("oip") , objNodeList.item(index).getAttribute("ogw") , objNodeList.item(index).getAttribute("osnm")
'退出循环
Exit For
End If
Next
End If
End Sub
'本方法用于创建访问内网的i.cmd文件
'本方法可与下一个方法合并为一个 懒得改了~~
Sub CreateCMDI( iip , igw , isnm )
Dim fso, f1
'创建FileSystemObject的调用
Set fso = CreateObject("Scripting.FileSystemObject")
'创建文本文件 地址可更改为%WinDir%/System32下
Set f1 = fso.CreateTextFile("c:/i.cmd", True)
f1.WriteLine "@echo off"
If igw = "" Then
'本地连接 应为变量 通过命令行应可解析得到 有待尝试
f1.WriteLine "netsh interface ip set address 本地连接 static " & iip & " " & isnm & " > nul"
Else
f1.WriteLine "netsh interface ip set address 本地连接 static " & iip & " " & isnm & " " & igm & " 1 > nul"
End If
f1.write "exit"
f1.close
End Sub
'本方法用于创建访问外网的o.cmd文件
Sub CreateCMDO( iip , igw , isnm )
Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:/o.cmd", True)
f1.WriteLine "@echo off"
If igw = "" Then
f1.WriteLine "netsh interface ip set address 本地连接 static " & iip & " " & isnm & " > nul"
Else
f1.WriteLine "netsh interface ip set address 本地连接 static " & iip & " " & isnm & " " & igm & " 1 > nul"
End If
f1.write "exit"
f1.close
End Sub
Call LoadIpMap
'*****************************************************************
'
'IPMAP.xml 文件示例
'
'<root>
' <!--
' 每一个machine节点为一台机器 其中
' mac指mac地址 ip为IP地址 gw为网关 snm为子网掩码
' 前缀i表示内网 o表示外网
'
' 如果机器数量较多 本文件可采用ARP命令辅助 自动生成
' -->
' <machine
' mac="00-05-5D-86-59-00"
' iip="192.168.0.112"
' igw="192.168.0.1"
' isnm="255.255.255.0"
' oip="10.62.1.189"
' ogw="10.62.1.1"
' osnm="255.255.0.0"
' />
'</root>
'
'*****************************************************************
- 自动切换网络访问脚本(不完全版)
- wifi eth gprs 网络自动切换 脚本
- 网络接口自动切换
- 切换网络连接的脚本
- 切换网络连接的脚本
- 自动切换网络IP 配置
- Python_博客自动访问脚本
- Windows下自动切换IP脚本
- 自动切换IP设置的脚本
- keepalive之mysql故障自动切换脚本
- python 脚本自动切换windows代理设置
- XP下 使用脚本,自动切换IP
- 路由路由脚本自动切换网关
- win10下自动切换ip脚本
- BGP网络访问跨地域实时切换
- 判断网络状况,切换访问主机地址
- Linux自动切换用户脚本,自动输入用户名密码
- 自动切换机器的网络配置
- Eclipse配置问题集锦
- jspSmartUpload上传下载全攻略
- 我的编译EZX例子的经历
- 4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000F0000000
- 重启IIS
- 自动切换网络访问脚本(不完全版)
- My_Diary
- 管理技巧:使用netsh.exe配置TCP/IP
- c++语句的编译译方式和i++的处理
- 阴雨天
- 网络经典命令行
- C++类学习
- 关于PE可执行文件的修改
- 利用PStore获取帐号信息