15 |
' http://www.activevb.de/rubriken/apikatalog/deklarationen/rasenumentries.html |
' http://www.activevb.de/rubriken/apikatalog/deklarationen/rasenumentries.html |
16 |
' http://www.dotnet247.com/247reference/msgs/18/93960.aspx |
' http://www.dotnet247.com/247reference/msgs/18/93960.aspx |
17 |
|
|
18 |
|
' contains all ras entry objects |
19 |
Public RasEntries As New Collection |
Public RasEntries As New Collection |
20 |
|
|
21 |
|
' globals to store connection name and state |
22 |
|
Public ConnectionName As String |
23 |
|
Public ConnectionOnline As Boolean |
24 |
|
|
25 |
|
' globals to store information about action to do on up|down |
26 |
|
Enum ActionTypes |
27 |
|
RUN_SCRIPT |
28 |
|
ADD_ROUTE |
29 |
|
End Enum |
30 |
|
Public ActionType As ActionTypes |
31 |
|
|
32 |
|
Public ScriptName As String |
33 |
|
Public RouteNet As String, RouteMask As String |
34 |
|
|
35 |
|
Const RouteMaskDefault As String = "255.255.255.0" |
36 |
|
|
37 |
|
|
38 |
Sub Main() |
Sub Main() |
39 |
|
|
40 |
Dim cmdline As New CommandLine |
Dim cmdline As New CommandLine |
77 |
ElseIf cmdline.hasSwitch("script") And success = True Then |
ElseIf cmdline.hasSwitch("script") And success = True Then |
78 |
script_name = cmdline.getArgument("script") |
script_name = cmdline.getArgument("script") |
79 |
If script_name <> "" Then |
If script_name <> "" Then |
80 |
script_args = Chr(34) & DetermineClientIP() & Chr(34) & " " & Chr(34) & DetermineServerIP & Chr(34) |
script_args = Chr(34) & DetermineClientIP(conName) & Chr(34) & " " & Chr(34) & DetermineServerIP(conName) & Chr(34) |
81 |
Shell App.Path & "\" & script_name & " " & script_args, vbHide |
Shell App.Path & "\" & script_name & " " & script_args, vbHide |
82 |
End If |
End If |
83 |
'End If |
'End If |
103 |
End If |
End If |
104 |
|
|
105 |
End If |
End If |
106 |
|
|
107 |
|
' monitor |
108 |
|
ElseIf cmdline.hasSwitch("monitor") Then |
109 |
|
conName = cmdline.getArgument("monitor") |
110 |
|
If conName <> "" Then |
111 |
|
|
112 |
|
' run script |
113 |
|
If cmdline.hasSwitch("script") Then |
114 |
|
ActionType = RUN_SCRIPT |
115 |
|
ScriptName = cmdline.getArgument("script") |
116 |
|
End If |
117 |
|
|
118 |
|
' add a route with target network via gateway |
119 |
|
If cmdline.hasSwitch("net") Then |
120 |
|
ActionType = ADD_ROUTE |
121 |
|
RouteNet = cmdline.getArgument("net") |
122 |
|
If cmdline.hasSwitch("mask") Then |
123 |
|
RouteMask = cmdline.getArgument("mask") |
124 |
|
Else |
125 |
|
RouteMask = RouteMaskDefault |
126 |
|
End If |
127 |
|
End If |
128 |
|
|
129 |
|
'Set rasItem = RasEntries(conName) |
130 |
|
'RasRetrieveConnectionHandler conName |
131 |
|
ConnectionName = conName |
132 |
|
ConnectionOnline = RasIsOnline(conName) |
133 |
|
MonitorRASStatusAsync |
134 |
|
End If |
135 |
|
|
136 |
End If |
End If |
137 |
|
|
138 |
'End If |
'End If |
162 |
Next i |
Next i |
163 |
|
|
164 |
End Sub |
End Sub |
165 |
|
|
166 |
|
' callback from MonitorRASStatusAsync |
167 |
|
Public Sub detectOnlineOfflineChange() |
168 |
|
Dim isOnline As Boolean |
169 |
|
Dim script_name As String, script_args As String |
170 |
|
Dim cmd As String |
171 |
|
|
172 |
|
isOnline = RasIsOnline(ConnectionName) |
173 |
|
|
174 |
|
If ConnectionOnline <> isOnline Then |
175 |
|
'MsgBox isOnline |
176 |
|
|
177 |
|
Select Case ActionType |
178 |
|
|
179 |
|
Case RUN_SCRIPT: |
180 |
|
script_name = ScriptName |
181 |
|
If script_name <> "" Then |
182 |
|
script_args = Chr(34) & DetermineClientIP(ConnectionName) & Chr(34) & " " & Chr(34) & DetermineServerIP(ConnectionName) & Chr(34) |
183 |
|
cmd = App.Path & "\" & script_name & " " & script_args |
184 |
|
End If |
185 |
|
|
186 |
|
Case ADD_ROUTE: |
187 |
|
' connection goes online |
188 |
|
If isOnline = True Then |
189 |
|
script_name = "route" |
190 |
|
script_args = "add " & RouteNet & " mask " & RouteMask & " " & DetermineClientIP(ConnectionName) |
191 |
|
cmd = script_name & " " & script_args |
192 |
|
|
193 |
|
' connection goes offline |
194 |
|
Else |
195 |
|
' Nothing to do in this case |
196 |
|
|
197 |
|
End If |
198 |
|
|
199 |
|
End Select |
200 |
|
|
201 |
|
If cmd <> "" Then |
202 |
|
'MsgBox cmd |
203 |
|
On Error Resume Next |
204 |
|
Shell cmd, vbHide |
205 |
|
'Shell cmd, vbNormalFocus |
206 |
|
'If Err.Number <> 0 Then |
207 |
|
' MsgBox "Error while calling cmd: " & cmd & vbCrLf & "Error-Number: " & Err.Number |
208 |
|
'End If |
209 |
|
On Error GoTo 0 |
210 |
|
End If |
211 |
|
|
212 |
|
ConnectionOnline = isOnline |
213 |
|
End If |
214 |
|
End Sub |