-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathmain.ps1
264 lines (216 loc) · 8.74 KB
/
main.ps1
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
<#
====================== Mon's Network Enumeration Tool With GUI ==========================
SYNOPSIS
This script presents a GUI for enumerating other devices on the LAN network..
USAGE
1. Run script with powershell
2. Input ip Range and select additional parameters
3. Press "Start Scan"
#>
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName Microsoft.VisualBasic
[System.Windows.Forms.Application]::EnableVisualStyles()
$tooltip1 = New-Object System.Windows.Forms.ToolTip
$ShowHelp={
Switch ($this.name) {
"start" {$tip = "Start Search"}
"ipsearch" {$tip = "Define the first part of the IP here"}
"startrange" {$tip = "Define the start of the IP range"}
"endrange" {$tip = "Define the start of the IP range"}
"hostname" {$tip = "Try to resolve each IP's hostname"}
"ssh" {$tip = "Test port 22 (ssh) on each IP"}
"manufact" {$tip = "Get any manufacturer details"}
}
$tooltip1.SetToolTip($this,$tip)
}
$MainWindow = New-Object System.Windows.Forms.Form
$MainWindow.ClientSize = '552,535'
$MainWindow.Text = "| beigetools | LAN Device Search & Enumeration |"
$MainWindow.BackColor = "#242424"
$MainWindow.Opacity = 0.93
$MainWindow.TopMost = $false
$MainWindow.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon("C:\Windows\System32\DevicePairingWizard.exe")
$OutputBox = New-Object System.Windows.Forms.TextBox
$OutputBox.Multiline = $True;
$OutputBox.Location = New-Object System.Drawing.Size(15,180)
$OutputBox.Width = 522
$OutputBox.Height = 340
$OutputBox.Scrollbars = "Vertical"
$OutputBox.Text = "----------------------------------- RESULTS -----------------------------------"
$OutputBox.Font = 'Microsoft Sans Serif,8,style=Bold'
$StartScan = New-Object System.Windows.Forms.Button
$StartScan.Text = "Start"
$StartScan.Width = 100
$StartScan.Height = 25
$StartScan.Location = New-Object System.Drawing.Point(435, 33)
$StartScan.Font = 'Microsoft Sans Serif,8,style=Bold'
$StartScan.BackColor = "#eeeeee"
$StartScan.add_MouseHover($showhelp)
$StartScan.name="start"
$sshboxtext = New-Object System.Windows.Forms.Label
$sshboxtext.Text = "Test for SSH"
$sshboxtext.ForeColor = "#bcbcbc"
$sshboxtext.AutoSize = $true
$sshboxtext.Width = 25
$sshboxtext.Height = 10
$sshboxtext.Location = New-Object System.Drawing.Point(35, 67)
$sshboxtext.Font = 'Microsoft Sans Serif,8,style=Bold'
$sshbox = New-Object System.Windows.Forms.CheckBox
$sshbox.Width = 20
$sshbox.Height = 20
$sshbox.Location = New-Object System.Drawing.Point(15, 65)
$sshbox.add_MouseHover($showhelp)
$sshbox.name="ssh"
$manufacturerboxtext = New-Object System.Windows.Forms.Label
$manufacturerboxtext.Text = "Include Manufacturer"
$manufacturerboxtext.ForeColor = "#bcbcbc"
$manufacturerboxtext.AutoSize = $true
$manufacturerboxtext.Width = 25
$manufacturerboxtext.Height = 10
$manufacturerboxtext.Location = New-Object System.Drawing.Point(35, 97)
$manufacturerboxtext.Font = 'Microsoft Sans Serif,8,style=Bold'
$manufacturerbox = New-Object System.Windows.Forms.CheckBox
$manufacturerbox.Width = 20
$manufacturerbox.Height = 20
$manufacturerbox.Location = New-Object System.Drawing.Point(15, 95)
$manufacturerbox.add_MouseHover($showhelp)
$manufacturerbox.name="manufact"
$hostnameboxtext = New-Object System.Windows.Forms.Label
$hostnameboxtext.Text = "Include Network Hostname"
$hostnameboxtext.ForeColor = "#bcbcbc"
$hostnameboxtext.AutoSize = $true
$hostnameboxtext.Width = 25
$hostnameboxtext.Height = 10
$hostnameboxtext.Location = New-Object System.Drawing.Point(35, 127)
$hostnameboxtext.Font = 'Microsoft Sans Serif,8,style=Bold'
$hostnamebox = New-Object System.Windows.Forms.CheckBox
$hostnamebox.Width = 20
$hostnamebox.Height = 20
$hostnamebox.Location = New-Object System.Drawing.Point(15, 125)
$hostnamebox.add_MouseHover($showhelp)
$hostnamebox.name="hostname"
$TextboxInputHeader = New-Object System.Windows.Forms.Label
$TextboxInputHeader.Text = "Search IP Range for All Devices"
$TextboxInputHeader.ForeColor = "#bcbcbc"
$TextboxInputHeader.AutoSize = $true
$TextboxInputHeader.Width = 25
$TextboxInputHeader.Height = 10
$TextboxInputHeader.Location = New-Object System.Drawing.Point(15, 15)
$TextboxInputHeader.Font = 'Microsoft Sans Serif,8,style=Bold'
$TextBoxInput = New-Object System.Windows.Forms.TextBox
$TextBoxInput.Location = New-Object System.Drawing.Point(15, 35)
$TextBoxInput.BackColor = "#eeeeee"
$TextBoxInput.Width = 140
$TextBoxInput.Height = 40
$TextBoxInput.Text = "192.168.0."
$TextBoxInput.Multiline = $false
$TextBoxInput.Font = 'Microsoft Sans Serif,8,style=Bold'
$TextBoxInput.add_MouseHover($showhelp)
$TextBoxInput.name="ipsearch"
$dashline = New-Object System.Windows.Forms.Label
$dashline.Text = "-"
$dashline.ForeColor = "#bcbcbc"
$dashline.AutoSize = $true
$dashline.Width = 25
$dashline.Height = 10
$dashline.Location = New-Object System.Drawing.Point(220, 35)
$dashline.Font = 'Microsoft Sans Serif,9,style=Bold'
$startip = New-Object System.Windows.Forms.TextBox
$startip.Location = New-Object System.Drawing.Point(170, 35)
$startip.BackColor = "#eeeeee"
$startip.Width = 50
$startip.Height = 40
$startip.Text = "1"
$startip.Multiline = $false
$startip.Font = 'Microsoft Sans Serif,8,style=Bold'
$startip.add_MouseHover($showhelp)
$startip.name="startrange"
$endip = New-Object System.Windows.Forms.TextBox
$endip.Location = New-Object System.Drawing.Point(230, 35)
$endip.BackColor = "#eeeeee"
$endip.Width = 50
$endip.Height = 40
$endip.Text = "254"
$endip.Multiline = $false
$endip.Font = 'Microsoft Sans Serif,8,style=Bold'
$endip.add_MouseHover($showhelp)
$endip.name="endrange"
#==================================================== Define GUI Elements ==========================================================
$MainWindow.controls.AddRange(@($TextBoxInput, $startip, $endip, $StartScan, $sshboxtext, $sshbox, $manufacturerboxtext, $manufacturerbox, $hostnameboxtext, $hostnamebox, $OutputBox, $TextboxInputHeader, $dashline))
#==================================================== Click Functions ==========================================================
$StartScan.Add_Click({
Function Add-OutputBoxLine{
Param ($outfeed)
$OutputBox.AppendText("`r`n$outfeed")
$OutputBox.Refresh()
$OutputBox.ScrollToCaret()
}
Add-OutputBoxLine -Outfeed "Starting scan..."
$FileOut = "$env:temp\Computers.csv"
$Subnet = $TextBoxInput.Text
$a=[int]$startip.text
$b=[int]$endip.text
$a..$b|ForEach-Object{
Start-Process -WindowStyle Hidden ping.exe -Argumentlist "-n 1 -l 0 -f -i 2 -w 100 -4 $SubNet$_"
}
$Computers = (arp.exe -a | Select-String "$SubNet.*dynam") -replace ' +',','|
ConvertFrom-Csv -Header Computername,IPv4,MAC,x,Vendor|
Select IPv4,MAC
$Computers | Export-Csv $FileOut -NotypeInformation
if($sshbox.Checked){
$data = Import-Csv "$env:temp\Computers.csv"
$data | Add-Member -MemberType NoteProperty -Name "ssh" -Value ""
$data | ForEach-Object {
$ip = $_.'IPv4'
try {
$tcpClient = New-Object System.Net.Sockets.TcpClient
$timeout = 2 * 1000 # 2 seconds timeout
$asyncResult = $tcpClient.BeginConnect($ip, 22, $null, $null)
$wait = $asyncResult.AsyncWaitHandle.WaitOne($timeout, $false)
if ($wait) {
$tcpClient.EndConnect($asyncResult)
$ssh = "Yes"
} else {
$ssh = "No"
}
$tcpClient.Close()
} catch {
$ssh = "Closed"
}
$_ | Add-Member -MemberType NoteProperty -Name "ssh" -Value $ssh -force
}
$data | Export-Csv "$env:temp\Computers.csv" -NoTypeInformation
}
if($manufacturerbox.Checked){
$data = Import-Csv "$env:temp\Computers.csv"
$data | Add-Member -MemberType NoteProperty -Name "manufacturer" -Value ""
$data | ForEach-Object {
$mac = $_.'MAC'
$apiUrl = "https://api.macvendors.com/" + $mac
$manufacturer = (Invoke-WebRequest -Uri $apiUrl).Content
start-sleep 1
$_ | Add-Member -MemberType NoteProperty -Name "manufacturer" -Value $manufacturer -force
}
$data | Export-Csv "$env:temp\Computers.csv" -NoTypeInformation
}
if($hostnamebox.Checked){
$data = Import-Csv "$env:temp\Computers.csv"
$data | Add-Member -MemberType NoteProperty -Name "Hostname" -Value ""
$data | ForEach-Object {
try{
$ip = $_.'IPv4'
$hostname = ([System.Net.Dns]::GetHostEntry($ip)).HostName
$_ | Add-Member -MemberType NoteProperty -Name "Hostname" -Value $hostname -force
} catch{
$_ | Add-Member -MemberType NoteProperty -Name "Hostname" -Value "Error: $($_.Exception.Message)"
}
}
$data | Export-Csv "$env:temp\Computers.csv" -NoTypeInformation
}
$textfile = Get-Content "$env:temp\Computers.csv" -Raw
Add-OutputBoxLine -Outfeed "$textfile"
})
#===================================================== Initialize Script ===================================================
$MainWindow.ShowDialog() | Out-Null
exit