'*****************************************************************
' 自动切换网络访问脚本(不完全版)
' 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>
'
' *****************************************************************