众所周知,我们用的PPPOE是动态IP的,所以想用IP地址限制我们是难了点!
以下这些代码是在以前的光盘上找的,没有作者,就算转贴吧,其实利用拨号的那个东东也能实现断线,但是我试了试有的机器上不行滴,就用了另外一种方式,所以代码比较杂,不过函数也没有什么参数,直接调用就行了,我们还是以好用为主!
使用时只要注意是拨号~~~而且你的WINDOWS拨号连接(WINDOWSXP自带的拨号,其他软件的话请参考相应的帮助文件,一般软件都应该支持命令行操作,那你就不用下面的代码了,直接写SHELL*****)已经设置好帐号和密码了~~~
以下是代码,放在模块内。(VB6 SP6 WINXP SP2测试通过)
Option Explicit
Private Declare Function RasHangUp Lib "RasApi32.dll" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long
Private Declare Function RasEnumConnections Lib "RasApi32.dll" Alias "RasEnumConnectionsA" (lprasconn As Any, lpcb As Long, lpcConnections As Long) As Long
Public Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias "RasGetConnectStatusA" (ByVal hRasCon As Long, lpStatus As Any) As Long
Const RAS95_MaxEntryName = 256
Const RAS95_MaxDeviceName = 128
Const RAS_MaxDeviceType = 16
Const RAS95_MaxDeviceType = 16
Private Type RASCONN95
'set dwsize to 412
dwSize As Long
hRasConn As Long
szEntryName(RAS95_MaxEntryName) As Byte
szDeviceType(RAS_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Public Type RASCONNSTATUS95
dwSize As Long
RasConnState As Long
dwError As Long
szDeviceType(RAS95_MaxDeviceType) As Byte
szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Const INTERNET_DIALSTATE_DISCONNECTED = 1
Const INTERNET_AUTODIAL_FORCE_ONLINE = 1
Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2
Const INTERNET_DIAL_UNATTENDED = &H8000
Dim iHandle As Long
Private Declare Function InternetDial Lib "wininet.dll" ( _
ByVal hwndParent As Long, _
ByVal lpszConnectoid As String, _
ByVal dwFlags As Long, _
lpdwConnection As Long, _
ByVal dwReserved As Long) As Long
'参数dwConnection指定拨号连接句柄
Private Declare Function InternetHangUp Lib "wininet.dll" _
(ByVal dwConnection As Long, _
ByVal dwReserved As Long) As Long
'断开
Public Sub CloseConnected()
Dim lngRetCode As Long
Dim lpcb As Long
Dim lpcConnections As Long
Dim intArraySize As Integer
Dim intLooper As Integer
ReDim lprasconn95(intArraySize) As RASCONN95
lprasconn95(0).dwSize = 412
lpcb = 256 * lprasconn95(0).dwSize
lngRetCode = RasEnumConnections(lprasconn95(0), lpcb, lpcConnections)
If lngRetCode = 0 Then
If lpcConnections > 0 Then
For intLooper = 0 To lpcConnections - 1
RasHangUp lprasconn95(intLooper).hRasConn
Next intLooper
Else
MsgBox "没有拨号网络连接!", vbInformation
End If
End If
End Sub
'检测
Public Function IsConnected() As Boolean '返回T时为连接
Dim TRasCon(255) As RASCONN95
Dim lg As Long
Dim lpcon As Long
Dim RetVal As Long
Dim Tstatus As RASCONNSTATUS95
'
TRasCon(0).dwSize = 412
lg = 256 * TRasCon(0).dwSize
'
RetVal = RasEnumConnections(TRasCon(0), lg, lpcon)
If RetVal <> 0 Then
MsgBox "产生错误!", vbInformation, "提示"
Exit Function
End If
'
Tstatus.dwSize = 160
RetVal = RasGetConnectStatus(TRasCon(0).hRasConn, Tstatus)
If Tstatus.RasConnState = &H2000 Then
IsConnected = True
Else
IsConnected = False
End If
End Function
'拨号
Public Function AddConnected()
'建立名称为wt的连接,连接成功后连接句柄保存在iHandel中
InternetDial Form1.hWnd, "wt", INTERNET_AUTODIAL_FORCE_UNATTENDED, iHandle, 0
End Function