$Range = 1..25
$Subnet = '10.133.3'
$Ports = 135,139,445,67,68,53,143,993,389,636,110,995,25,119,563,21,20,80,443,531,2053,543,464,88,544
foreach ($Octet in $Range)
{
$IPAddress = "$($Subnet).$($Octet)"
$IP = $null
$Mac = $null
$MacAddress = $null
$PortList = @()
try
{
$IP = Test-Connection -ComputerName $IPAddress -Count 1 -ErrorAction Stop
$Mac = (&;; arp -a $IP.Address)
$MacAddress = ($mac | ? { $_ -match $IP.Address } ) -match "([0-9A-F]{2}([:-][0-9A-F]{2}){5})"
if ($Matches)
{
try
{
$mac = [system.net.networkinformation.physicaladdress]::parse($Matches[0].ToUpper())
}
catch
{
$mac = ''
}
}
foreach ($Port in $Ports)
{
$Socket = New-Object System.Net.Sockets.TcpClient
$Socket.Client.ReceiveTimeout = 1000
$Socket.Client.SendTimeout = 2000
try
{
$Socket.Connect($IP.Address, $port)
$Result = $Socket.Connected
if ($Result -eq $true)
{
$Portlist += $Port
}
}
catch
{
}
$Socket.Close()
}
$Name = [System.Net.Dns]::GetHostEntry($IP.Address).Hostname
New-Object -TypeName PSObject -Property @{
IP = $IP.Address
Name = $Name
MAC = $Mac
PortList = $PortList
}
}
catch
{
$Message = $Error[0].Exception
#Write-Host $Message
$IP = $null
$Mac = $null
$MacAddress = $null
}
}