打算暑假基本就宅在寝室了,不怎么想去实验室了。
顺便去买个6M的闪讯帐号,再连个无线路由,室友也可以用,手机也可以用用。同学给了个破解的程序,可以用的,只是比较麻烦。每次先在主机是用官方客户端连接,会生成一个新的ChinaNetSNWide连接,再手动把连接共享,再用破解程序来保持连接,而Windows上的连接共享会改变IP,所以每次分机都需要把网关改为主机的IP,当然首先在保证ICS(Internet Connection Sharing)服务开启了。。于是就想到了用批处理来自动完成,免了手动去改共享和IP。
ics.vbs
@echo off
echo 开始设置主机固定IP地址!请稍候……
echo 出现防火墙提示请点击允许!
netsh interface ip set address "Wireless Network Connection 2" static 192.168.1.100 255.255.255.0 192.168.1.1 1
echo 设置DNS服务器!请稍候……
echo 出现防火墙提示请点击允许!
netsh interface ip set dns "Wireless Network Connection 2" static 8.8.8.8 primary
netsh interface ip add dns "Wireless Network Connection 2" 8.8.4.4
echo IP地址: 192.168.1.100
echo 子网掩码: 255.255.255.0
echo 默认网关: 192.168.1.1
echo DNS服务器:
echo 8.8.8.8
echo 8.8.4.4
pause
changeip.bat主要是用于主机的IP更改,定死了IP为192.168.1.100,方便后面分机的网关填写。
'用法 cscript /nologo ics.vbs "内网适配器名称" "外网网络连接名称" "off/on"
OPTION EXPLICIT
DIM ICSSC_DEFAULT, CONNECTION_PUBLIC, CONNECTION_PRIVATE, CONNECTION_ALL
DIM NetSharingManager
DIM PublicConnection, PrivateConnection
DIM EveryConnectionCollection
DIM objArgs
DIM priv_con, publ_con
DIM switch
ICSSC_DEFAULT = 0
CONNECTION_PUBLIC = 0
CONNECTION_PRIVATE = 1
CONNECTION_ALL = 2
Main()
sub Main( )
Set objArgs = WScript.Arguments
if objArgs.Count = 3 then
priv_con = objArgs(0) '内网适配器名称
publ_con = objArgs(1) '外网网络连接名称
switch = objArgs(2) '状态切换开关 on 为打开 off 相反
if Initialize() = TRUE then
GetConnectionObjects()
FirewallTestByDeviceName priv_con,publ_con
end if
else
if Initialize() = TRUE then
GetConnectionObjects()
FirewallTestByDeviceName "list","list"
end if
end if
end sub
sub FirewallTestByDeviceName(con1,con2)
on error resume next
DIM Item
DIM EveryConnection
DIM objNCProps
DIM szMsg
DIM bFound1,bFound2
WScript.echo(vbCRLF)
bFound1 = false
bFound2 = false
for each Item in EveryConnectionCollection
set EveryConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
set objNCProps = NetSharingManager.NetConnectionProps(Item)
szMsg = "Name: " & objNCProps.Name & vbCRLF & _
"Guid: " & objNCProps.Guid & vbCRLF & _
"DeviceName: " & objNCProps.DeviceName & vbCRLF & _
"Status: " & objNCProps.Status & vbCRLF & _
"MediaType: " & objNCProps.MediaType
if EveryConnection.SharingEnabled then
szMsg = szMsg & vbCRLF & _
"SharingEnabled" & vbCRLF & _
"SharingType: " & ConvertConnectionTypeToString(EveryConnection.SharingConnectionType)
end if
if objNCProps.DeviceName = con1 then
bFound1 = true
if EveryConnection.SharingEnabled = False and switch="on" then
szMsg = szMsg & vbCRLF & "Not Shared... Enabling private connection share..."
EveryConnection.EnableSharing CONNECTION_PRIVATE
end if
if switch="off" then
szMsg = szMsg & vbCRLF & "Shared... DisEnabling private connection share..."
EveryConnection.EnableSharing CONNECTION_ALL
end if
end if
if objNCProps.Name = con2 then
bFound2 = true
if EveryConnection.SharingEnabled = False and switch="on" then
szMsg = szMsg & vbCRLF & "Not Shared... Enabling public connection share..."
EveryConnection.EnableSharing CONNECTION_PUBLIC
end if
if switch="off" then
szMsg = szMsg & vbCRLF & "Shared... DisEnabling public connection share..."
EveryConnection.EnableSharing CONNECTION_ALL
end if
end if
WScript.Echo(szMsg & vbCRLF)
next
if( con1 <> "list" ) then
if( bFound1 = false ) then
WScript.Echo( "Connection " & chr(34) & con1 & chr(34) & " was not found" )
end if
if( bFound2 = false ) then
WScript.Echo( "Connection " & chr(34) & con2 & chr(34) & " was not found" )
end if
end if
end sub
function Initialize()
DIM bReturn
bReturn = FALSE
set NetSharingManager = Wscript.CreateObject("HNetCfg.HNetShare.1")
if (IsObject(NetSharingManager)) = FALSE then
Wscript.Echo("Unable to get the HNetCfg.HnetShare.1 object")
else
if (IsNull(NetSharingManager.SharingInstalled) = TRUE) then
Wscript.Echo("Sharing isn't available on this platform.")
else
bReturn = TRUE
end if
end if
Initialize = bReturn
end function
function GetConnectionObjects()
DIM bReturn
DIM Item
bReturn = TRUE
if GetConnection(CONNECTION_PUBLIC) = FALSE then
bReturn = FALSE
end if
if GetConnection(CONNECTION_PRIVATE) = FALSE then
bReturn = FALSE
end if
if GetConnection(CONNECTION_ALL) = FALSE then
bReturn = FALSE
end if
GetConnectionObjects = bReturn
end function
function GetConnection(CONNECTION_TYPE)
DIM bReturn
DIM Connection
DIM Item
bReturn = TRUE
if (CONNECTION_PUBLIC = CONNECTION_TYPE) then
set Connection = NetSharingManager.EnumPublicConnections(ICSSC_DEFAULT)
if (Connection.Count > 0) and (Connection.Count < 2) then
for each Item in Connection
set PublicConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
next
else
bReturn = FALSE
end if
elseif (CONNECTION_PRIVATE = CONNECTION_TYPE) then
set Connection = NetSharingManager.EnumPrivateConnections(ICSSC_DEFAULT)
if (Connection.Count > 0) and (Connection.Count < 2) then
for each Item in Connection
set PrivateConnection = NetSharingManager.INetSharingConfigurationForINetConnection(Item)
next
else
bReturn = FALSE
end if
elseif (CONNECTION_ALL = CONNECTION_TYPE) then
set Connection = NetSharingManager.EnumEveryConnection
if (Connection.Count > 0) then
set EveryConnectionCollection = Connection
else
bReturn = FALSE
end if
else
bReturn = FALSE
end if
if (TRUE = bReturn) then
if (Connection.Count = 0) then
Wscript.Echo("No " + CStr(ConvertConnectionTypeToString(CONNECTION_TYPE)) + " connections exist (Connection.Count gave us 0)")
bReturn = FALSE
'valid to have more than 1 connection returned from EnumEveryConnection
elseif (Connection.Count > 1) and (CONNECTION_ALL <> CONNECTION_TYPE) then
Wscript.Echo("ERROR: There was more than one " + ConvertConnectionTypeToString(CONNECTION_TYPE) + " connection (" + CStr(Connection.Count) + ")")
bReturn = FALSE
end if
end if
Wscript.Echo(CStr(Connection.Count) + " objects for connection type " + ConvertConnectionTypeToString(CONNECTION_TYPE))
GetConnection = bReturn
end function
function ConvertConnectionTypeToString(ConnectionID)
DIM ConnectionString
if (ConnectionID = CONNECTION_PUBLIC) then
ConnectionString = "public"
elseif (ConnectionID = CONNECTION_PRIVATE) then
ConnectionString = "private"
elseif (ConnectionID = CONNECTION_ALL) then
ConnectionString = "all"
else
ConnectionString = "Unknown: " + CStr(ConnectionID)
end if
ConvertConnectionTypeToString = ConnectionString
end function
ics.vbs是在网上找的,可以用于ICS的开启,虽不懂VB,但会调用就行了,要注意参数一个是内网适配器名称,另一个是外网网络连接名称。
Changeip.bat
@echo off
echo 确定闪讯已连接成功???
pause
Start "" "闪讯终结者.exe"
echo 闪讯终结者运行成功!
cscript /nologo ics.vbs "Atheros AR5B97 Wireless Network Adapter" "ChinaNetSNWide" "on"
echo ics 开启成功!
pause
Changeip.bat
echo ip切换完成,请手动退出闪讯客户端!!!
pause
Changeip.bat对于主机只要运行这个批处理就行了。
Client.bat
@echo off
cls
echo 开始设置固定IP地址!请稍候……
echo 出现防火墙提示请点击允许!
netsh interface ip set address "Wireless Network Connection 2" static 192.168.1.110 255.255.255.0 192.168.1.100 1
echo 设置DNS服务器!请稍候……
echo 出现防火墙提示请点击允许!
netsh interface ip set dns "Wireless Network Connection 2" static 8.8.8.8 primary
netsh interface ip add dns "Wireless Network Connection 2" 8.8.4.4
cls
echo 设置已经完成!
echo IP地址: 192.168.1.110
echo 子网掩码: 255.255.255.0
echo 默认网关: 192.168.1.100
echo DNS服务器:
echo 8.8.8.8
echo 8.8.4.4
pause
Client.bat是给分机用的,主要是把网关改成主机的IP,且自己的IP不要和别的重复就行了。