forked from chall32/LDWin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLDWin.au3
307 lines (299 loc) · 13.2 KB
/
LDWin.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#NoTrayIcon
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=network.ico
#AutoIt3Wrapper_Outfile=LDWin.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Description=Link Discovery for Windows
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Res_LegalCopyright=Chris Hall 2010-2013
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_Res_Field=ProductName|LDWin
#AutoIt3Wrapper_Res_Field=ProductVersion|1.0
#AutoIt3Wrapper_Res_Field=OriginalFileName|LDWin.exe
#AutoIt3Wrapper_Run_AU3Check=n
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;===================================================================================================================================================================
; LDWin - Link Discovery for Windows - Chris Hall 2010-2013
;===================================================================================================================================================================
$VER = "1.0"
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <String.au3>
#include <GuiButton.au3>
#include <ComboConstants.au3>
$WinLDPVer = "LDWin - v" & $VER & " - Chris Hall - 2010-" & @YEAR
If IsAdmin() = 0 Then
MsgBox(16, "Exiting", "This program requires Local Admistrator rights")
Exit
EndIf
FileInstall("tcpdump.exe", @TempDir & '\', 1)
GUISetIcon("network.ico")
$log = FileOpen(@TempDir & "\LinkData.txt", 2)
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output = ""
$Nic_Friend = ""
$Hardware = ""
$IData = ""
SplashTextOn("Please Wait", "Enumerating Network Cards via WMI...", 300, 50)
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
FileWriteLine($log, "[" & $objItem.NetConnectionID & "]")
FileWriteLine($log, "ProductName=" & $objItem.ProductName)
$value = $objItem.NetConnectionID
If StringLen($value) > 1 Then $Output = $Output & $value & "|"
$colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
For $objItem2 In $colItems2
If $objItem.Index = $objItem2.Index Then
FileWriteLine($log, "SettingID=" & $objItem2.SettingID)
EndIf
Next
Next
Else
MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration")
EndIf
SplashOff()
$gui = GUICreate("Link Discovery for Windows", 550, 400, (@DesktopWidth - 550) / 2, (@DesktopHeight - 400) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
GUICtrlCreateGroup("Selection ", 15, 10, 520, 110)
GUICtrlCreateLabel("Network Connection:", 30, 35, 100, 20)
$Nic_Friendly = GUICtrlCreateCombo("", 145, 33, 350, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, $Output)
GUICtrlCreateLabel("Network Card:", 30, 62, 100, 20)
$Get = GUICtrlCreateButton("Get Link Data", 90, 85, 100)
$Save = GUICtrlCreateButton("Save Link Data", 200, 85, 100)
$Help = GUICtrlCreateButton("Help", 310, 85, 100)
$Cancel = GUICtrlCreateButton("Cancel", 420, 85, 100)
If RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLUA") > 0 Then
GUICtrlSetImage($Get, "imageres.dll", -2, 0)
_GUICtrlButton_SetShield($Get)
EndIf
GUICtrlCreateGroup("Results ", 15, 130, 520, 160)
GUICtrlCreateLabel("Switch Name:", 30, 160, 70, 20)
GUICtrlCreateLabel("Port Identifier:", 30, 190, 70, 20)
GUICtrlCreateLabel("VLAN Identifier:", 30, 220, 75, 20)
GUICtrlCreateLabel("Switch IP Address:", 30, 250, 90, 20)
GUICtrlCreateLabel("Switch Model:", 280, 190, 70, 20)
GUICtrlCreateLabel("Port Duplex:", 280, 220, 70, 20)
GUICtrlCreateLabel("VTP Mgmt Domain:", 280, 250, 95, 20)
GUICtrlCreateGroup("Status ", 15, 300, 520, 65)
GUICtrlCreateLabel($WinLDPVer, 350, 375, 275, 20)
While 1
Switch GUIGetMsg()
Case $Nic_Friendly
$Nic_Friend = GUICtrlRead($Nic_Friendly)
$IData = IniReadSection(@TempDir & "\LinkData.txt", $Nic_Friend)
$Hardware = $IData[1][1]
GUICtrlCreateLabel($Hardware, 145, 62, 350, 20)
ClearResults()
Case $Get
If GUICtrlRead($Nic_Friendly) = "" Then
MsgBox(64, "Invalid Selection", "Please select a network card using the dropdown")
ContinueLoop
EndIf
GetCDP($Nic_Friendly)
Case $GUI_EVENT_CLOSE
OnExit()
ExitLoop
Case $Cancel
OnExit()& @CRLF & _
ExitLoop
Case $Save
SaveData()
Case $Help
MsgBox(0, " Link Discovery for Windows : Help", "What is Link Discovery?" & @CRLF & _
"-------------------------" & @CRLF & _
"Link discovery is the process of ascertaining information from directly connected networking devices, such as network switches. " & _
"This can be helpful when diagnosing suspected network connectivity issues." & @CRLF & @CRLF & _
"LDWin supports the following methods of link discovery:" & @CRLF & _
"------------------------------------------------------------" & @CRLF & _
" - CDP : Cisco Discovery Protocol" & @CRLF & _
" - LLDP : Link Layer Discovery Protocol" & @CRLF & @CRLF & _
"How to Use:" & @CRLF & _
"-------------"& @CRLF & _
"1. From the 'Network Connection:' drop down, select the network adaptor over which you wish to obtain network link information" & @CRLF & @CRLF & _
"2. Click 'Get Link Data'"& @CRLF & @CRLF & _
"3. LDWin will then listen on the selected network adaptor for link protocol announcements. It may take up to 60 seconds to receive an announcement" & @CRLF & @CRLF & _
"4. Once an announcement has been received, the received information will be displayed in the results section" & @CRLF & @CRLF & _
"5. Use the 'Save Link Data' button to save the received information into a text file" & @CRLF & @CRLF & _
"NOTE:"& @CRLF & _
"------" & @CRLF & _
"A valid TCP/IP address is not required to receive link information"& @CRLF & @CRLF & _
" LDWin - v" & $VER & " - Chris Hall - 2010-" & @YEAR & " - chall32.blogspot.com")
Case Else
;;;
EndSwitch
WEnd
Exit
Func GetCDP($Nic_Friendly)
$SaveFile = FileOpen(@TempDir & "\SaveData.txt", 2)
GUICtrlSetState($Get, $GUI_DISABLE)
GUICtrlSetState($Save, $GUI_DISABLE)
GUICtrlSetState($Help, $GUI_DISABLE)
ClearResults()
FileWriteLine($SaveFile, $Nic_Friend & " (" & $Hardware & ") is connected to:")
FileWriteLine($SaveFile, "------------------------------------------------------")
$ID = $IData[2][1]
;******** DIAG MODE ********
$TCPDmpPID = Run(@ComSpec & " /c " & @TempDir & '\tcpdump.exe -i \Device\' & $ID & ' -nn -v -s 1500 -c 1 ether[20:2] == 0x2000 >%temp%\Data_Out.txt', "", @SW_HIDE)
;$TCPDmpPID = "0"
;******** DIAG MODE ********
$Secs = 1
$Status1 = GUICtrlCreateLabel("Running ... May take up to 60 seconds between link announcements ...", 120, 320, 350, 20)
$iBegin = TimerInit()
Do
$msg = GUIGetMsg()
If $msg = $Cancel Then
ProcessClose("tcpdump.exe")
ExitLoop
EndIf
If Ceiling(TimerDiff($iBegin)) = ($Secs * 1000) Or Ceiling(TimerDiff($iBegin)) > ($Secs * 1000) Then
GUICtrlCreateLabel(Round($Secs, 0) & " Seconds elapsed", 240, 340, 100, 20)
$Secs = $Secs + 1
EndIf
$TCPDmpPID = ProcessExists($TCPDmpPID)
Until $TCPDmpPID = "0" Or TimerDiff($iBegin) > 60000
GUICtrlDelete($Status1)
GUICtrlCreateLabel("", 240, 337, 100, 20)
GUICtrlCreateLabel("", 210, 317, 200, 20)
$file = FileOpen(@TempDir & "\Data_Out.txt")
$end = _FileCountLines(@TempDir & "\Data_Out.txt")
If $end > 0 Then
$line = 0
Do
;===== CDP ==========================================================================
If StringInStr(FileReadLine($file, $line), "Device-ID (0x01)") Then
$SwitchName = StringSplit(FileReadLine($file, $line), "'")
$SwitchName = StringUpper($SwitchName[2])
GUICtrlCreateLabel($SwitchName, 140, 160, 370, 20)
FileWriteLine($SaveFile, "Switch Name: " & $SwitchName)
EndIf
If StringInStr(FileReadLine($file, $line), "Port-ID (0x03)") Then
$SwitchPort = StringSplit(FileReadLine($file, $line), "'")
GUICtrlCreateLabel($SwitchPort[2], 140, 190, 120, 20)
FileWriteLine($SaveFile, "Switch Port: " & $SwitchPort[2])
EndIf
If StringInStr(FileReadLine($file, $line), "VLAN ID (0x0a)") Then
$VLAN = StringSplit(FileReadLine($file, $line), ":")
$VLAN = StringStripWS($VLAN[3], 8)
GUICtrlCreateLabel($VLAN, 140, 220, 120, 20)
FileWriteLine($SaveFile, "VLAN ID: " & $VLAN)
EndIf
If StringInStr(FileReadLine($file, $line), "Address (0x02)") Then
$SwitchIP = StringSplit(FileReadLine($file, $line), ")")
$SwitchIP = StringStripWS($SwitchIP[3], 8)
GUICtrlCreateLabel($SwitchIP, 140, 250, 120, 20)
FileWriteLine($SaveFile, "Switch IP: " & $SwitchIP)
EndIf
If StringInStr(FileReadLine($file, $line), "Platform (0x06)") Then
$SwitchModel = StringSplit(FileReadLine($file, $line), "'")
$SwitchModel = StringUpper($SwitchModel[2])
If StringInStr($SwitchModel, "CISCO") Then
$SwitchModel = StringTrimLeft(StringUpper($SwitchModel), 6)
EndIf
GUICtrlCreateLabel($SwitchModel, 390, 190, 120, 20)
FileWriteLine($SaveFile, "Switch Model: " & $SwitchModel)
EndIf
If StringInStr(FileReadLine($file, $line), "Duplex (0x0b)") Then
$Duplex = StringSplit(FileReadLine($file, $line), ":")
$Duplex = StringLower(StringStripWS($Duplex[3], 8))
$Duplex = _StringProper($Duplex)
GUICtrlCreateLabel($Duplex, 390, 220, 120, 20)
FileWriteLine($SaveFile, "Switch Duplex: " & $Duplex)
EndIf
If StringInStr(FileReadLine($file, $line), "VTP Management Domain (0x09)") Then
$VTP = StringSplit(FileReadLine($file, $line), "'")
GUICtrlCreateLabel($VTP[2], 390, 250, 120, 20)
FileWriteLine($SaveFile, "VTP Mgmt: " & $VTP[2])
EndIf
;===== LLDP =========================================================================
If StringInStr(FileReadLine($file, $line), "System Name TLV (5)") Then
$SwitchName = StringSplit(FileReadLine($file, $line), ":")
$SwitchName = StringStripWS(StringUpper($SwitchName[2]), 3)
GUICtrlCreateLabel($SwitchName, 140, 160, 370, 20)
FileWriteLine($SaveFile, "Switch Name: " & $SwitchName)
EndIf
If StringInStr(FileReadLine($file, $line), "Port Description TLV (4)") Then
$SwitchPort = StringSplit(FileReadLine($file, $line), ":")
$SwitchPort = StringStripWS($SwitchPort[2], 3)
GUICtrlCreateLabel($SwitchPort, 140, 190, 120, 40)
FileWriteLine($SaveFile, "Switch Port: " & $SwitchPort)
EndIf
If StringInStr(FileReadLine($file, $line), "port vlan id (PVID)") Then
$VLAN = StringSplit(FileReadLine($file, $line), ":")
$VLAN = StringStripWS($VLAN[2], 3)
GUICtrlCreateLabel($VLAN, 140, 220, 120, 20)
FileWriteLine($SaveFile, "VLAN ID: " & $VLAN)
EndIf
If StringInStr(FileReadLine($file, $line), "Management Address TLV (8)") Then
$SwitchIP = StringSplit(FileReadLine($file, $line), ":")
If @error Then
$nextline = $line + 1
$SwitchIP = StringSplit(FileReadLine($file, $nextline), ":")
Else
$SwitchIP = $SwitchIP[2]
EndIf
$SwitchIP = StringStripWS(StringUpper($SwitchIP[2]), 3)
GUICtrlCreateLabel($SwitchIP, 140, 250, 120, 20)
FileWriteLine($SaveFile, "Switch IP: " & $SwitchIP)
EndIf
If StringInStr(FileReadLine($file, $line), "System Description TLV (6)") Then
$SwitchModel = StringSplit(FileReadLine($file, $line), ":")
If @error Then
$nextline = $line + 1
$SwitchModel = FileReadLine($file, $nextline)
Else
$SwitchModel = $SwitchModel[2]
EndIf
$SwitchModel = StringStripWS($SwitchModel, 3)
GUICtrlCreateLabel($SwitchModel, 390, 190, 120, 40)
FileWriteLine($SaveFile, "Switch Model: " & $SwitchModel)
EndIf
$line = $line + 1
Until $line = $end
Else
If ProcessExists("tcpdump.exe") Then ProcessClose("tcpdump.exe")
GUICtrlCreateLabel("NO LINK DATA FOUND ... !", 210, 325, 150, 20)
FileClose($SaveFile)
FileDelete(@TempDir & "\SaveData.txt")
EndIf
FileClose($SaveFile)
FileClose($file)
;******** DIAG MODE ********
FileDelete(@TempDir & "\Data_Out.txt")
;******** DIAG MODE ********
GUICtrlSetState($Get, $GUI_ENABLE)
GUICtrlSetState($Save, $GUI_ENABLE)
GUICtrlSetState($Help, $GUI_ENABLE)
EndFunc ;==>GetCDP
Func ClearResults()
GUICtrlCreateLabel("", 140, 160, 180, 20)
GUICtrlCreateLabel("", 140, 190, 120, 20)
GUICtrlCreateLabel("", 140, 220, 120, 20)
GUICtrlCreateLabel("", 140, 250, 120, 20)
GUICtrlCreateLabel("", 390, 190, 120, 20)
GUICtrlCreateLabel("", 390, 220, 120, 20)
GUICtrlCreateLabel("", 390, 250, 120, 20)
EndFunc ;==>ClearResults
Func SaveData()
If FileExists(@TempDir & "\SaveData.txt") = 0 Then Return
$UserSave = FileSaveDialog("Save Link Data to", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Text Documents (*.txt)", 2)
If $UserSave = "" Then Return
If StringInStr($UserSave, ".txt") = 0 Then $UserSave = $UserSave & ".txt"
FileOpen($UserSave, 1)
FileWrite($UserSave, FileRead(@TempDir & "\SaveData.txt") & @CRLF)
FileClose($UserSave)
EndFunc ;==>SaveData
Func OnExit()
If ProcessExists("tcpdump.exe") Then ProcessClose("tcpdump.exe")
FileClose($log)
FileDelete(@TempDir & "\LinkData.txt")
FileDelete(@TempDir & "\tcpdump.exe")
FileDelete(@TempDir & "\SaveData.txt")
EndFunc ;==>OnExit