Posts Tagged openvpn

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



用ros做openvpn服务端win客户端无法获得网关的解决办法

Posted by on 星期二, 30 十一月, 2010

  用下面的配置文件,这样就可以解决,注意最后3行配置:

client
dev tap
proto tcp
remote wolf.awolf.net 1194
ca ca.crt
keepalive 10 120
cipher AES-256-CBC
auth SHA1
auth-user-pass
verb 5
route-method exe
route-delay 2
route add 0.0.0.0 mask 0.0.0.0 192.168.27.254 metric 1

  route-method exe #通过win自带的route.exe执行路由添加命令
  route-delay 2 #延迟2秒后执行
  route add 0.0.0.0 mask 0.0.0.0 192.168.27.254 metric 1 #添加网关为192.168.27.254且跳计数为1的默认路由

  还需要注意的是,ros做服务端不支持udp连接方式和lzo压缩。

在Ros上实现基于OpenVPN的WolfLAN

Posted by on 星期五, 11 六月, 2010

  为了方便,我用VB重写了OpenVPN客户端,实际上就是gui版的OpenVPN,加上了一些检测机制,用于我和朋友们之间联机对战和资料共享,并重新命名为WolfLAN(单击下载客户端)

  由于OpenVPN拨入服务与内网接口同在一个桥里,因此拨入后可以直接通过DHCP获得内网IP,并且与本地LAN在同一个广播域里。目前经过测试,cs,魔兽,红警(IPX),星际,三角洲,暗黑,极品飞车,实况足球都全都成功联机。

Ros脚本:


[wolf@router_ros_330_wolf] /interface ovpn-server> export
# jun/10/2010 21:27:01 by RouterOS 3.30
# software id = QXLB-EYHG
#
/interface ovpn-server server
set auth=sha1 certificate=cert_wolf cipher=aes128 default-profile=ovpn_server
enabled=yes keepalive-timeout=60 mac-address=FE:36:F9:7F:32:0A max-mtu=\
1500 mode=ethernet netmask=24 port=1194 require-client-certificate=no
[wolf@router_ros_330_wolf] /interface ovpn-server>
[wolf@router_ros_330_wolf] /ppp profile> export
/ppp profile
add bridge=LAN change-tcp-mss=no comment="" dns-server=192.168.27.254 local-address=\
pool_master name=ovpn_server only-one=no rate-limit=512k/512k remote-address=\
pool_master use-compression=yes use-encryption=required use-vj-compression=yes \
wins-server=192.168.27.250
[wolf@router_ros_330_wolf] /ppp profile>

客户端代码:

client
dev tap
proto tcp
remote wolf.awolf.net 1194
ca ca.crt
keepalive 10 120
cipher AES-256-CBC
auth SHA1
auth-user-pass
verb 5

 

成功应用的ros版本为3.30 L6

需要ros 3.30 L6 的请看这里 《RouterOS 3.20 算号器 新版本 10分钟内算出指定id》

WolfLAN源码:http://www.awolf.net/content/vb/wolflan-source.html