Posts Tagged source

WolfLAN源码和简单原理介绍

Posted by on 星期一, 28 三月, 2011

>>WolfLAN源码下载<<


  在登录时等待OpenVPN返回“Enter Auth Username”和“Enter Auth Password”,然后将帐号密码送入管道。之后读取管道,根据OpenVPN输出来判断当前状态。


登录代码:


PipeClosed = False
txtLog.Text = Now & vbCrLf
Set OvpnPipe = New ClsPipe
OvpnPipe.ConsoleShell = strAppPath & "openvpn.exe --config " & Chr(34) & strAppPath & "Wolf.ovpn" & Chr(34) '以指定参数在管道中运行OpenVPN
OvpnPipe.Silent = True
OvpnPipe.CreateConsolePipe
tmrLog.Enabled = True
'等待输入用户名并发送用户名===================
Do While InStr(1, txtLog.Text, "Enter Auth Username:") = 0
DoEvents
Loop
lbMsg.ToolTipText = "验证用户名和密码"
OvpnPipe.WriteToPipe txtUserName.Text
'===========================================
'等待输入密码并发送密码======================
Do While InStr(1, txtLog.Text, "Enter Auth Password:") = 0
DoEvents
Loop
OvpnPipe.WriteToPipe txtPassword.Text


状态判断:


If InStr(1, txtLog.Text, "TUN/TAP interface has been stopped") <> 0 Then
ConnectError
lbMsg.Caption = "- 网卡已停止"
Exit Sub
End If
DoEvents
If InStr(1, txtLog.Text, "process exiting") <> 0 Then
ConnectError
lbMsg.Caption = "- 进程终止"
Exit Sub
End If
DoEvents
If InStr(1, txtLog.Text, "Closing TUN/TAP interface") <> 0 Then
ConnectError
lbMsg.Caption = "- 网卡关闭"
Exit Sub
End If
DoEvents
If InStr(1, txtLog.Text, "There are no TAP-Win32 adapters on this system.") <> 0 Then
ConnectError
lbMsg.Caption = "- 未找到Tap网卡"
Exit Sub
End If
DoEvents
If InStr(1, txtLog.Text, "All TAP-Win32 adapters on this system are currently in use.") <> 0 Then
ConnectError
lbMsg.Caption = "- 网卡被占用"
Exit Sub
End If
DoEvents
If (InStr(1, txtLog.Text, "TCP/UDP: Closing socket") <> 0) And (InStr(1, txtLog.Text, "Restart pause, 5 second(s)") <> 0) Then
ConnectError
lbMsg.Caption = "- 错误:Closing socket"
Exit Sub
End If
DoEvents
If InStr(1, txtLog.Text, "Exiting") <> 0 Then
ConnectError
lbMsg.Caption = "- 主动断开"
Exit Sub
End If
DoEvents
If (InStr(1, txtLog.Text, "VERIFY OK") <> 0) And (InStr(1, txtLog.Text, "--dhcp-option") = 0) Then lbMsg.ToolTipText = "建立通道"
If (InStr(1, txtLog.Text, "--dhcp-option") <> 0) And (InStr(1, txtLog.Text, "Initialization Sequence Completed") = 0) Then lbMsg.ToolTipText = "获取IP"
If (InStr(1, txtLog.Text, "Initialization Sequence Completed") <> 0) And (InStr(1, txtLog.Text, "With Errors") = 0) Then
If chkRoute.Value = 1 Then
lbMsg.ToolTipText = "设置借线"
OvpnPipe.Wait (2000)
WaitRun "route", "add 0.0.0.0 mask 0.0.0.0 192.168.27.254"
End If
lbMsg.Caption = "+ 链接成功"
SocketsInitialize
tmrStatus.Enabled = False
cmdLogin.Enabled = True
cmdLogin.Caption = "&D.断开"
PopInfo
Exit Sub
End If
DoEvents
If InStr(1, txtLog.Text, "Initialization Sequence Completed With Errors") <> 0 Then
ConnectError
lbMsg.Caption = "- Errors"
Exit Sub
End If
DoEvents