Get-InternetAccessInfo.psm1
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 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# # Created by: lucas.cueff[at]lucas-cueff.com # # v0.1 : initial release # Released on: 03/2018 # #'(c) 2018 lucas-cueff.com - Distributed under Artistic Licence 2.0 (https://opensource.org/licenses/artistic-license-2.0).' <# .SYNOPSIS simple PowerShell module to get all information regarding the way your endpoint is connected to internet .DESCRIPTION multiple functions are used to retrieve all information regarding your external network access usefull on a unknown host to find how the external network access is working informations retrieved : - network status from network location awareness / network location manager - settings of NLA service - all settings (proxy mainly) set for each network connections - winhttp settings - internet settings - wpad settings .EXAMPLE C:\PS> import-module Get-InternetAccessInfo.psm1 #> function Get-NLAInfo { <# .SYNOPSIS function used to retrieve Network Location Awareness information .DESCRIPTION Network location awareness automates several network test (icmp, dns, http) to detect the current network environment (type, category, connectivity) .PARAMETER NetworkStatus -NetworkStatus string from the following list : 'AllNetworks','ConnectedNetworks','DisconnectedNetworks' mandatory type of network interface you want to check : all, only the connected ones, only the disconnected ones. .OUTPUTS TypeName : System.Management.Automation.PSCustomObject Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() Domain Type NoteProperty string Domain Type=NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK Network Category NoteProperty string Network Category=NLM_NETWORK_CATEGORY_PUBLIC Network Connectivity NoteProperty Object[] Network Connectivity=System.Object[] Network Name NoteProperty string Network Name=XYZ .EXAMPLE Get all information from NLA for the connected network interfaces C:\PS> Get-NLAInfo -NetworkStatus ConnectedNetworks #> [cmdletbinding()] param( [parameter(Mandatory=$true)] [ValidateSet('AllNetworks','ConnectedNetworks','DisconnectedNetworks')] [string]$NetworkStatus ) $NetworkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID('DCB00C01-570F-4A9B-8D69-199FDBA5723B')) $NLM_ENUM_NETWORK_CONNECTED=1 $NLM_ENUM_NETWORK_DISCONNECTED=2 $NLM_ENUM_NETWORK_ALL=3 $NetCategories = @{ 0x00="NLM_NETWORK_CATEGORY_PUBLIC"; 0x01="NLM_NETWORK_CATEGORY_PRIVATE"; 0x02="NLM_NETWORK_CATEGORY_DOMAIN_AUTHENTICATED" } $DomainTypes = @{ 0x00="NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK"; 0x01="NLM_DOMAIN_TYPE_DOMAIN_NETWORK"; 0x02="NLM_DOMAIN_TYPE_DOMAIN_AUTHENTICATED" } $NLMConnectivity = @{ 0x0000="NLM_CONNECTIVITY_DISCONNECTED"; 0x0001="NLM_CONNECTIVITY_IPV4_NOTRAFFIC"; 0x0002="NLM_CONNECTIVITY_IPV6_NOTRAFFIC"; 0x0010="NLM_CONNECTIVITY_IPV4_SUBNET"; 0x0020="NLM_CONNECTIVITY_IPV4_LOCALNETWORK"; 0x0040="NLM_CONNECTIVITY_IPV4_INTERNET"; 0x0100="NLM_CONNECTIVITY_IPV6_SUBNET"; 0x0200="NLM_CONNECTIVITY_IPV6_LOCALNETWORK"; 0x0400="NLM_CONNECTIVITY_IPV6_INTERNET" } Switch ($NetworkStatus) { 'AllNetworks' {$Networks = $NetworkListManager.GetNetworks($NLM_ENUM_NETWORK_ALL)} 'ConnectedNetworks' {$Networks = $NetworkListManager.GetNetworks($NLM_ENUM_NETWORK_CONNECTED)} 'DisconnectedNetworks' {$Networks = $NetworkListManager.GetNetworks($NLM_ENUM_NETWORK_DISCONNECTED)} } $AllNetworkObjects = @() foreach($Network in $Networks){ $AllConnectivityStatus = @() foreach($Key in $NLMConnectivity.Keys){ $KeyBand = $Key -band $Network.GetConnectivity() if($KeyBand -gt 0){ $AllConnectivityStatus += $NLMConnectivity.Get_Item($KeyBand) } } $NetworkObject = [PSCustomObject]@{ 'Network Name' = $Network.GetName() 'Domain Type' = $DomainTypes.Get_Item($Network.GetDomainType()) 'Network Category' = $NetCategories.Get_Item($Network.GetCategory()) 'Network Connectivity' = $AllConnectivityStatus } $AllNetworkObjects += $NetworkObject } return $AllNetworkObjects } Function Get-WinHttpProxy { <# .SYNOPSIS function used to retrieve proxy set for local machine web layer aka winhttp .DESCRIPTION retrieve proxy set for local machine web layer aka winhttp .OUTPUTS TypeName : System.Management.Automation.PSCustomObject Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() Winhttp proxy NoteProperty string Winhttp proxy=Direct Access Winhttp proxy bypass list NoteProperty string Winhttp proxy bypass list=(none) .EXAMPLE Get all information about winhttp proxy C:\PS> Get-WinHttpProxy #> [CmdletBinding()] Param() try { $Conprx = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" -Name WinHttpSettings).WinHttpSettings } catch { $Conprx = $null } finally { if ($Conprx) { $proxylength = $Conprx[12] if ($proxylength -gt 0) { $proxy = -join ($Conprx[(12+3+1)..(12+3+1+$proxylength-1)] | ForEach-Object {([char]$_)}) $bypasslength = $Conprx[(12+3+1+$proxylength)] if ($bypasslength -gt 0) { $bypasslist = -join ($Conprx[(12+3+1+$proxylength+3+1)..(12+3+1+$proxylength+3+1+$bypasslength)] | ForEach-Object {([char]$_)}) } else { $bypasslist = '(none)' } $result = [PSCustomObject]@{ "Winhttp proxy" = $proxy "Winhttp proxy bypass list" = $bypasslist } } else { $result = [PSCustomObject]@{ "Winhttp proxy" = "Direct Access" "Winhttp proxy bypass list" = "(none)" } } } else { $result = [PSCustomObject]@{ "Winhttp proxy" = "error - not able to read registry entry" "Winhttp proxy bypass list" = "error - not able to read registry entry" } } } return $result } Function Get-UserconnectionProxy { <# .SYNOPSIS function used to retrieve proxy information for all network connection used by the current user context .DESCRIPTION retrieve proxy information for all network connection used by the current user context .OUTPUTS TypeName : System.Management.Automation.PSCustomObject Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() User proxy NoteProperty string User proxy=proxy.cc.dddddd.io:8080 User proxy bypass list NoteProperty string User proxy bypass list=test;<local>) User proxy connection name NoteProperty string User proxy connection name=SavedLegacySettings User proxy PAC NoteProperty string User proxy PAC=http://xxxxxx.yy.zzzz.io:8080/ .EXAMPLE Get all information about user connections C:\PS> Get-UserconnectionProxy #> [CmdletBinding()] Param() try { $Conprx = Get-Item "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" } catch { $Conprx = $null } finally { $results = @() if ($Conprx) { $ConRegValues = $Conprx.GetValueNames() foreach ($value in $ConRegValues) { $result = [PSCustomObject]@{ "User proxy connection name" = $value } $tmpvalue = $Conprx.GetValue($value) $pacentr = $null for($i=0;$i -le $tmpvalue.length;$i++){ if (($tmpvalue[$i] -eq 36) -or ($tmpvalue[$i] -eq 41)) { $pacentr = $i break } } if ($pacentr) { $proxypac = -join ($tmpvalue[($pacentr+3+1)..($pacentr+3+1+$tmpvalue.length-1)] | ForEach-Object {([char]$_)}) $Result | add-member -MemberType NoteProperty -Name "User proxy PAC" -Value $proxypac } else { $Result | add-member -MemberType NoteProperty -Name "User proxy PAC" -Value "none" } $proxylength = $tmpvalue[12] if ($proxylength -gt 0) { $proxy = -join ($tmpvalue[(12+3+1)..(12+3+1+$proxylength-1)] | ForEach-Object {([char]$_)}) $bypasslength = $tmpvalue[(12+3+1+$proxylength)] if ($bypasslength -gt 0) { $bypasslist = -join ($tmpvalue[(12+3+1+$proxylength+3+1)..(12+3+1+$proxylength+3+1+$bypasslength)] | ForEach-Object {([char]$_)}) } else { $bypasslist = '(none)' } $Result | add-member -MemberType NoteProperty -Name "User proxy" -Value $proxy $Result | add-member -MemberType NoteProperty -Name "User proxy bypass list" -value $bypasslist } else { $Result | add-member -MemberType NoteProperty -Name "User proxy" -value "Direct Access" $Result | add-member -MemberType NoteProperty -Name "User proxy bypass list" -value "(none)" } $results += $result } } else { $result = [PSCustomObject]@{ "User connection proxy" = "error - not able to read registry entry" } $results += $result } } return $results } Function Get-NLAServiceInfo { <# .SYNOPSIS function used to retrieve windows service paramareters for all NLA service .DESCRIPTION function used to retrieve windows service paramareters for all NLA service : - DNS, HTTP endpoint used for test, IPV4 and IPV6 endpoint used for test .OUTPUTS TypeName : System.Management.Automation.PSCustomObject Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() NLA Check Disabled By Policy NoteProperty bool NLA Check Disabled By Policy=False NLA Service Settings NoteProperty hashtable NLA Service Settings=System.Collections.Hashtable .EXAMPLE Get all information about NLA service parameters C:\PS> Get-NLAServiceInfo #> [CmdletBinding()] Param() $NLASettings=@{} try { $NLASVCSettings = Get-Item "hklm:\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet" } catch { $NLASVCSettings = $null } finally { if ($NLASVCSettings) { $SvcRegValues = $NLASVCSettings.GetValueNames() } foreach ($value in $SvcRegValues) { $NLASettings.add($value,$NLASVCSettings.GetValue($value)) } } try { $NLAPolicyKey = Get-Item "hklm:\SOFTWARE\Policies\Microsoft\Windows\NetworkConnectivityStatusIndicator" $NLAPolicyIndicatorValue = $NLAPolicyKey.GetValue("EnableActiveProbing") } catch { $NLAPolicyKey = $null } Finally { if ($NLAPolicyIndicatorValue -eq 0) { $NLACheckDisabledByPolicy = $true } Else { $NLACheckDisabledByPolicy = $false } } $SettingsObject = [PSCustomObject]@{ 'NLA Service Settings' = $NLASettings 'NLA Check Disabled By Policy' = $NLACheckDisabledByPolicy } return $SettingsObject } Function Get-InternetAccessInfo { <# .SYNOPSIS main function calling all other functions available in the module do build a global summary of all available information regarding the internet access of the computer/user .DESCRIPTION main function calling all other functions available in the module do build a global summary of all available information regarding the internet access of the computer/user .OUTPUTS TypeName : System.Management.Automation.PSCustomObject Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() Internet settings NoteProperty System.Management.Automation.PSCustomObject Internet settings=@{User Proxy=False; Use... NLA NoteProperty Object[] NLA=System.Object[] NLA service NoteProperty System.Management.Automation.PSCustomObject NLA service=@{NLA Service Settings=System... User connections NoteProperty Object[] User connections=System.Object[] Winhttp NoteProperty System.Management.Automation.PSCustomObject Winhttp=@{Winhttp proxy=Direct Access; Wi... .EXAMPLE Get all information about current user/machine internet access C:\PS> Get-InternetAccessInfo #> [CmdletBinding()] Param() $Result = [PSCustomObject]@{ "NLA" = (Get-NLAInfo -NetworkStatus 'ConnectedNetworks') "NLA service"= Get-NLAServiceInfo "Winhttp" = Get-WinHttpProxy "User connections" = Get-UserconnectionProxy "Internet settings" = Get-UserInternetSettings } return $Result } Function Get-UserInternetSettings { <# .SYNOPSIS function used to get : - all information regarding your basic internet settings used by Internet Explorer/Edge or third party browser like Goole Chrome/Chromium - wpad settings .DESCRIPTION function used to get : - all information regarding your basic internet settings used by Internet Explorer/Edge or third party browser like Goole Chrome/Chromium - wpad settings .OUTPUTS TypeName : System.Management.Automation.PSCustomObject Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() Force Disable WPAD NoteProperty bool Force Disable WPAD=False User Proxy NoteProperty bool User Proxy=False User Proxy Autoconfig URL NoteProperty object User Proxy Autoconfig URL=null User Proxy HTTP1.1 NoteProperty bool User Proxy HTTP1.1=False User Proxy Migrate NoteProperty bool User Proxy Migrate=True User Proxy server NoteProperty string User Proxy server=proxy.xx.yyyyyyyyyyyyyyy.io:8080 User Proxy WPAD NoteProperty bool User Proxy WPAD=False WPAD Service Status NoteProperty ServiceControllerStatus WPAD Service Status=Running .EXAMPLE Get all information regarding your basic internet settings C:\PS> Get-UserInternetSettings #> [CmdletBinding()] Param() $Results=[PSCustomObject]@{} try { $InternetSettings = Get-Item "hkcu:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" } catch { $InternetSettings = $null } finally { if ($InternetSettings) { try { [bool]$booltmp = $InternetSettings.GetValue("ProxyEnable") } catch { $booltmp = $false } finally { $Results | add-member -MemberType NoteProperty -Name "User Proxy" -Value $booltmp } try { [bool]$booltmp2 = $InternetSettings.GetValue("ProxyHTTP1.1") } catch { $booltmp2 = $false } finally { $Results | add-member -MemberType NoteProperty -Name "User Proxy HTTP1.1" -Value $booltmp2 } $Results | add-member -MemberType NoteProperty -Name "User Proxy server" -Value $InternetSettings.GetValue("ProxyServer") $Results | add-member -MemberType NoteProperty -Name "User Proxy Autoconfig URL" -Value $InternetSettings.GetValue("AutoConfigURL") try { [bool]$booltmp3 = $InternetSettings.GetValue("AutoDetect") } catch { $booltmp3 = $false } finally { $Results | add-member -MemberType NoteProperty -Name "User Proxy WPAD" -Value $booltmp3 } try { [bool]$booltmp4 = $InternetSettings.GetValue("MigrateProxy") } catch { $booltmp4 = $false } finally { $Results | add-member -MemberType NoteProperty -Name "User Proxy Migrate" -Value $booltmp4 } } } try { $WPADSettings = Get-Item "hkcu:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\WPAD" } catch { $WPADSettings = $null } finally { if ($WPADSettings.GetValue("WpadOverride")) { [bool]$booltmp5 = $WPADSettings.GetValue("WpadOverride") $Results | add-member -MemberType NoteProperty -Name "Force Disable WPAD" -Value $booltmp5 } Else { $Results | add-member -MemberType NoteProperty -Name "Force Disable WPAD" -Value $false } } try { $WPADServiceStatus = (Get-Service WinHttpAutoProxySvc).status } catch { $WPADServiceStatus = $null } finally { If ($WPADServiceStatus) { $Results | add-member -MemberType NoteProperty -Name "WPAD Service Status" -Value $WPADServiceStatus } else { $Results | add-member -MemberType NoteProperty -Name "WPAD Service Status" -Value "N/A" } } return $results } Export-ModuleMember -Function Get-NLAInfo,Get-NLAServiceInfo,Get-UserconnectionProxy,Get-WinHttpProxy,Get-InternetAccessInfo,Get-UserInternetSettings |