|
| 1 | +#region >> Helper Functions |
| 2 | + |
| 3 | +function TestIsValidIPAddress([string]$IPAddress) { |
| 4 | + [boolean]$Octets = (($IPAddress.Split(".") | Measure-Object).Count -eq 4) |
| 5 | + [boolean]$Valid = ($IPAddress -as [ipaddress]) -as [boolean] |
| 6 | + Return ($Valid -and $Octets) |
| 7 | +} |
| 8 | + |
| 9 | +function ResolveHost { |
| 10 | + [CmdletBinding()] |
| 11 | + Param( |
| 12 | + [Parameter(Mandatory=$True)] |
| 13 | + [string]$HostNameOrIP |
| 14 | + ) |
| 15 | + |
| 16 | + ##### BEGIN Main Body ##### |
| 17 | + |
| 18 | + $RemoteHostNetworkInfoArray = @() |
| 19 | + if (!$(TestIsValidIPAddress -IPAddress $HostNameOrIP)) { |
| 20 | + try { |
| 21 | + $HostNamePrep = $HostNameOrIP |
| 22 | + [System.Collections.ArrayList]$RemoteHostArrayOfIPAddresses = @() |
| 23 | + $IPv4AddressFamily = "InterNetwork" |
| 24 | + $IPv6AddressFamily = "InterNetworkV6" |
| 25 | + |
| 26 | + $ResolutionInfo = [System.Net.Dns]::GetHostEntry($HostNamePrep) |
| 27 | + $ResolutionInfo.AddressList | Where-Object { |
| 28 | + $_.AddressFamily -eq $IPv4AddressFamily |
| 29 | + } | foreach { |
| 30 | + if ($RemoteHostArrayOfIPAddresses -notcontains $_.IPAddressToString) { |
| 31 | + $null = $RemoteHostArrayOfIPAddresses.Add($_.IPAddressToString) |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + catch { |
| 36 | + Write-Verbose "Unable to resolve $HostNameOrIP when treated as a Host Name (as opposed to IP Address)!" |
| 37 | + |
| 38 | + if ($HostNameOrIP -match "\.") { |
| 39 | + try { |
| 40 | + $HostNamePrep = $($HostNameOrIP -split "\.")[0] |
| 41 | + Write-Verbose "Trying to resolve $HostNameOrIP using only HostName: $HostNamePrep!" |
| 42 | + |
| 43 | + [System.Collections.ArrayList]$RemoteHostArrayOfIPAddresses = @() |
| 44 | + $ResolutionInfo = [System.Net.Dns]::GetHostEntry($HostNamePrep) |
| 45 | + $ResolutionInfo.AddressList | Where-Object { |
| 46 | + $_.AddressFamily -eq $IPv4AddressFamily |
| 47 | + } | foreach { |
| 48 | + if ($RemoteHostArrayOfIPAddresses -notcontains $_.IPAddressToString) { |
| 49 | + $null = $RemoteHostArrayOfIPAddresses.Add($_.IPAddressToString) |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + catch { |
| 54 | + Write-Verbose "Unable to resolve $HostNamePrep!" |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + if (TestIsValidIPAddress -IPAddress $HostNameOrIP) { |
| 60 | + try { |
| 61 | + $HostIPPrep = $HostNameOrIP |
| 62 | + [System.Collections.ArrayList]$RemoteHostArrayOfIPAddresses = @() |
| 63 | + $null = $RemoteHostArrayOfIPAddresses.Add($HostIPPrep) |
| 64 | + |
| 65 | + $ResolutionInfo = [System.Net.Dns]::GetHostEntry($HostIPPrep) |
| 66 | + |
| 67 | + [System.Collections.ArrayList]$RemoteHostFQDNs = @() |
| 68 | + $null = $RemoteHostFQDNs.Add($ResolutionInfo.HostName) |
| 69 | + } |
| 70 | + catch { |
| 71 | + Write-Verbose "Unable to resolve $HostNameOrIP when treated as an IP Address (as opposed to Host Name)!" |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + if ($RemoteHostArrayOfIPAddresses.Count -eq 0) { |
| 76 | + Write-Error "Unable to determine IP Address of $HostNameOrIP! Halting!" |
| 77 | + $global:FunctionResult = "1" |
| 78 | + return |
| 79 | + } |
| 80 | + |
| 81 | + # At this point, we have $RemoteHostArrayOfIPAddresses... |
| 82 | + [System.Collections.ArrayList]$RemoteHostFQDNs = @() |
| 83 | + foreach ($HostIP in $RemoteHostArrayOfIPAddresses) { |
| 84 | + try { |
| 85 | + $FQDNPrep = [System.Net.Dns]::GetHostEntry($HostIP).HostName |
| 86 | + } |
| 87 | + catch { |
| 88 | + Write-Verbose "Unable to resolve $HostIP. No PTR Record? Please check your DNS config." |
| 89 | + continue |
| 90 | + } |
| 91 | + if ($RemoteHostFQDNs -notcontains $FQDNPrep) { |
| 92 | + $null = $RemoteHostFQDNs.Add($FQDNPrep) |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + if ($RemoteHostFQDNs.Count -eq 0) { |
| 97 | + $null = $RemoteHostFQDNs.Add($ResolutionInfo.HostName) |
| 98 | + } |
| 99 | + |
| 100 | + [System.Collections.ArrayList]$HostNameList = @() |
| 101 | + [System.Collections.ArrayList]$DomainList = @() |
| 102 | + foreach ($fqdn in $RemoteHostFQDNs) { |
| 103 | + $PeriodCheck = $($fqdn | Select-String -Pattern "\.").Matches.Success |
| 104 | + if ($PeriodCheck) { |
| 105 | + $HostName = $($fqdn -split "\.")[0] |
| 106 | + $Domain = $($fqdn -split "\.")[1..$($($fqdn -split "\.").Count-1)] -join '.' |
| 107 | + } |
| 108 | + else { |
| 109 | + $HostName = $fqdn |
| 110 | + $Domain = "Unknown" |
| 111 | + } |
| 112 | + |
| 113 | + $null = $HostNameList.Add($HostName) |
| 114 | + $null = $DomainList.Add($Domain) |
| 115 | + } |
| 116 | + |
| 117 | + if ($RemoteHostFQDNs[0] -eq $null -and $HostNameList[0] -eq $null -and $DomainList -eq "Unknown" -and $RemoteHostArrayOfIPAddresses) { |
| 118 | + [System.Collections.ArrayList]$SuccessfullyPingedIPs = @() |
| 119 | + # Test to see if we can reach the IP Addresses |
| 120 | + foreach ($ip in $RemoteHostArrayOfIPAddresses) { |
| 121 | + try { |
| 122 | + $null = [System.Net.NetworkInformation.Ping]::new().Send($ip,1000) |
| 123 | + $null = $SuccessfullyPingedIPs.Add($ip) |
| 124 | + } |
| 125 | + catch { |
| 126 | + Write-Verbose "Unable to ping $ip..." |
| 127 | + continue |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + $FQDNPrep = if ($RemoteHostFQDNs) {$RemoteHostFQDNs[0]} else {$null} |
| 133 | + if ($FQDNPrep -match ',') { |
| 134 | + $FQDN = $($FQDNPrep -split ',')[0] |
| 135 | + } |
| 136 | + else { |
| 137 | + $FQDN = $FQDNPrep |
| 138 | + } |
| 139 | + |
| 140 | + $DomainPrep = if ($DomainList) {$DomainList[0]} else {$null} |
| 141 | + if ($DomainPrep -match ',') { |
| 142 | + $Domain = $($DomainPrep -split ',')[0] |
| 143 | + } |
| 144 | + else { |
| 145 | + $Domain = $DomainPrep |
| 146 | + } |
| 147 | + |
| 148 | + $IPAddressList = [System.Collections.ArrayList]@($(if ($SuccessfullyPingedIPs) {$SuccessfullyPingedIPs} else {$RemoteHostArrayOfIPAddresses})) |
| 149 | + $HName = if ($HostNameList) {$HostNameList[0].ToLowerInvariant()} else {$null} |
| 150 | + |
| 151 | + if ($SuccessfullyPingedIPs.Count -eq 0 -and !$FQDN -and !$HostName -and !$Domain) { |
| 152 | + Write-Error "Unable to resolve $HostNameOrIP! Halting!" |
| 153 | + $global:FunctionResult = "1" |
| 154 | + return |
| 155 | + } |
| 156 | + |
| 157 | + [pscustomobject]@{ |
| 158 | + IPAddressList = $IPAddressList |
| 159 | + PingSuccess = $($SuccessfullyPingedIPs.Count -gt 0) |
| 160 | + FQDN = $FQDN |
| 161 | + HostName = $HName |
| 162 | + Domain = $Domain |
| 163 | + } |
| 164 | + |
| 165 | + ##### END Main Body ##### |
| 166 | + |
| 167 | +} |
| 168 | + |
| 169 | +function InstallLinuxPackage { |
| 170 | + [CmdletBinding()] |
| 171 | + Param ( |
| 172 | + [Parameter(Mandatory=$True)] |
| 173 | + [string[]]$PossiblePackageNames, |
| 174 | + |
| 175 | + [Parameter(Mandatory=$True)] |
| 176 | + [string]$CommandName |
| 177 | + ) |
| 178 | + |
| 179 | + if (!$(command -v $CommandName)) { |
| 180 | + foreach ($PackageName in $PossiblePackageNames) { |
| 181 | + if ($(command -v pacman)) { |
| 182 | + $null = pacman -S $PackageName --noconfirm *> $null |
| 183 | + } |
| 184 | + elseif ($(command -v yum)) { |
| 185 | + $null = yum -y install $PackageName *> $null |
| 186 | + } |
| 187 | + elseif ($(command -v dnf)) { |
| 188 | + $null = dnf -y install $PackageName *> $null |
| 189 | + } |
| 190 | + elseif ($(command -v apt)) { |
| 191 | + $null = apt -y install $PackageName *> $null |
| 192 | + } |
| 193 | + elseif ($(command -v zypper)) { |
| 194 | + $null = zypper install $PackageName --non-interactive *> $null |
| 195 | + } |
| 196 | + |
| 197 | + if ($(command -v $CommandName)) { |
| 198 | + break |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + if (!$(command -v $CommandName)) { |
| 203 | + Write-Error "Unable to find the command $CommandName! Install unsuccessful! Halting!" |
| 204 | + $global:FunctionResult = "1" |
| 205 | + return |
| 206 | + } |
| 207 | + else { |
| 208 | + Write-Host "$PackageName was successfully installed!" -ForegroundColor Green |
| 209 | + } |
| 210 | + } |
| 211 | + else { |
| 212 | + Write-Warning "The command $CommandName is already available!" |
| 213 | + return |
| 214 | + } |
| 215 | +} |
| 216 | + |
| 217 | +#endregion >> Helper Functions |
| 218 | + |
| 219 | + |
1 | 220 | function Get-SSHProbe {
|
2 | 221 | [CmdletBinding(DefaultParameterSetName='Domain')]
|
3 | 222 | Param (
|
@@ -1429,15 +1648,11 @@ function Get-SSHProbe {
|
1429 | 1648 |
|
1430 | 1649 | $FinalOutput
|
1431 | 1650 | }
|
1432 |
| - |
1433 |
| - |
1434 |
| - |
1435 |
| - |
1436 | 1651 | # SIG # Begin signature block
|
1437 | 1652 | # MIIMiAYJKoZIhvcNAQcCoIIMeTCCDHUCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
|
1438 | 1653 | # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
|
1439 |
| -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUOyPgxGVQ2e5w47rBFmRajJKO |
1440 |
| -# Kuegggn9MIIEJjCCAw6gAwIBAgITawAAAB/Nnq77QGja+wAAAAAAHzANBgkqhkiG |
| 1654 | +# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUKlxyQOThHQ+ECBDSTHQ9D349 |
| 1655 | +# PJSgggn9MIIEJjCCAw6gAwIBAgITawAAAB/Nnq77QGja+wAAAAAAHzANBgkqhkiG |
1441 | 1656 | # 9w0BAQsFADAwMQwwCgYDVQQGEwNMQUIxDTALBgNVBAoTBFpFUk8xETAPBgNVBAMT
|
1442 | 1657 | # CFplcm9EQzAxMB4XDTE3MDkyMDIxMDM1OFoXDTE5MDkyMDIxMTM1OFowPTETMBEG
|
1443 | 1658 | # CgmSJomT8ixkARkWA0xBQjEUMBIGCgmSJomT8ixkARkWBFpFUk8xEDAOBgNVBAMT
|
@@ -1494,11 +1709,11 @@ function Get-SSHProbe {
|
1494 | 1709 | # ARkWA0xBQjEUMBIGCgmSJomT8ixkARkWBFpFUk8xEDAOBgNVBAMTB1plcm9TQ0EC
|
1495 | 1710 | # E1gAAAH5oOvjAv3166MAAQAAAfkwCQYFKw4DAhoFAKB4MBgGCisGAQQBgjcCAQwx
|
1496 | 1711 | # CjAIoAKAAKECgAAwGQYJKoZIhvcNAQkDMQwGCisGAQQBgjcCAQQwHAYKKwYBBAGC
|
1497 |
| -# NwIBCzEOMAwGCisGAQQBgjcCARUwIwYJKoZIhvcNAQkEMRYEFBXBHIuzpm/BqWyE |
1498 |
| -# hBgeQvG06cfdMA0GCSqGSIb3DQEBAQUABIIBAGzB0WkLuIBYsdqVZ8yuDeiWP5Sc |
1499 |
| -# sfDEHU9YfiTskAk+/KY2i1Ai5siQoOQvL/xLaZhC9bUL21oJc9eDnA2jza5xSUS0 |
1500 |
| -# rKX3M1pYAy2Klp1uJqH1XXHDPdovZSwvZvibVqRMLC3qnCTvCe13sNem8mB7xk8I |
1501 |
| -# uvQ1/qo8E38MZAh4jgH5VKTa/P2z1ibnBx0+iA0oP0QSc9gnlWu7oqD6FdTGJCKC |
1502 |
| -# 4SQkR0LZ4BxVDWpsPwt1WME0XUfsd3Zn3DnwLLA/mXUpmxdI3YAhQPYGizxQ1rhy |
1503 |
| -# pWYbiWIJ3gwTaU6x2AVUNNr9x9faz6uLN/qiT4oFEiVq9bmCmTGmT7Izzfg= |
| 1712 | +# NwIBCzEOMAwGCisGAQQBgjcCARUwIwYJKoZIhvcNAQkEMRYEFD6RTK1z9lnRuK5F |
| 1713 | +# FT/5qO8DyfzMMA0GCSqGSIb3DQEBAQUABIIBALEl4gXPCjdDZkOK8I9eQ0qwzItK |
| 1714 | +# yPLAJ1d7kCZQcv8+knqfWCa56nqtMSKDC8CxPhqsEeVtwwfdMlaJQ0yywxwGxNyV |
| 1715 | +# VDdoiA2VxzsE99zJXA+lQy02oIBOwZWYrzY3oZumT1j0sgeAZ/G+/QrVYspI55kb |
| 1716 | +# RWBZX6fMaudd1PLFdaBrfHXXdIg1PHdIoNjGaKPPkTvZsGejq+Ae+Q4mIcnA93OJ |
| 1717 | +# 9/3bq/nIufowvP8yRYVque2syNp5mQLhnfiTv5AZF3JTmw3icAheEIewTTAJmjpR |
| 1718 | +# ksjo0NpfYqmL0c+dF6BKtxLBLAxXw10X0AM2B3mZ5wOw5eqwb7Vk2WBawJA= |
1504 | 1719 | # SIG # End signature block
|
0 commit comments