forked from securethelogs/Powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Subnetscanner
56 lines (29 loc) · 1.17 KB
/
Subnetscanner
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
$subnetrange = Read-Host -Prompt " [Subnet]:"
$iprange = @(1..254)
Write-Output ""
Write-Host " [*] Current Network: "; Write-Host $subnet -ForegroundColor Green
Write-Output ""
Write-Host "Scanning........"
Write-Output ""
foreach ($i in $iprange){
$currentip = $subnetrange + $i
$islive = test-connection $currentip -Quiet -Count 1
if ($islive -eq "True"){
try{$dnstest = (Resolve-DnsName $currentip -ErrorAction SilentlyContinue).NameHost}catch{}
if ($dnstest -like "*.home") {
$dnstest = $dnstest -replace ".home",""
}
Write-Output ""
Write-Host "Host is Reachable: " -NoNewline ; Write-Host $currentIP -ForegroundColor Green -NoNewline; Write-Host " | DNS: " -NoNewline ; Write-Host $dnstest -ForegroundColor Green
# ------- Scanning host ---------
$portstoscan = @(20,21,22,80,110,135,136,137,138,139,443,445,1443,3389,5985,5986)
$waittime = 100
foreach ($p in $portstoscan){
$TCPObject = new-Object system.Net.Sockets.TcpClient
try{$result = $TCPObject.ConnectAsync($currentip,$p).Wait($waittime)}catch{}
if ($result -eq "True"){
Write-Host "Port Open: " -NoNewline ; Write-Host $p -ForegroundColor Green
}
}
}
}