IP Configuration Toolkit
<# .SYNOPSIS IP Configuration Toolkit .DESCRIPTION This script provides comprehensive analysis and management options for IP configurations on Windows systems. .NOTES File Name : IPConfigToolkit.ps1 Author : [Your Name] Prerequisite : PowerShell V5.1 or later, and appropriate admin rights Version : 1.0 Date : [Current Date] .EXAMPLE .\IPConfigToolkit.ps1 #> # Global variables $global:reportPath = "$env:USERPROFILE\Desktop\IP_Config_Analysis_Report_$(Get-Date -Format 'yyyyMMdd_HHmmss').html" $global:targetComputer = $env:COMPUTERNAME # Default to local machine function Show-Menu { Clear-Host Write-Host "=== IP Configuration Toolkit ===" -ForegroundColor Cyan Write-Host "Current Target Computer: $global:targetComputer" Write-Host "1. Set Target Computer" Write-Host "2. Get IP Configuration" Write-Host "3. Analyze Network Adapters" Write-Host "4. Check DNS Settings" Write-Host "5. Perform Network Connectivity Tests" Write-Host "6. View Routing Table" Write-Host "7. Check Network Shares" Write-Host "8. Analyze Open Ports" Write-Host "9. View Network Statistics" Write-Host "10. Generate Comprehensive HTML Report" Write-Host "11. Exit" } function Set-TargetComputer { $computer = Read-Host "Enter the target computer name (or press Enter for localhost)" if ([string]::IsNullOrWhiteSpace($computer)) { $global:targetComputer = $env:COMPUTERNAME } else { $global:targetComputer = $computer } Write-Host "Target computer set to: $global:targetComputer" -ForegroundColor Green } function Get-IPConfiguration { Write-Host "`nGathering IP Configuration..." -ForegroundColor Yellow try { $ipConfig = Invoke-Command -ComputerName $global:targetComputer -ScriptBlock { Get-NetIPConfiguration | Select-Object InterfaceAlias, IPv4Address, IPv6Address, DNSServer } $ipConfig | Format-Table -AutoSize return $ipConfig } catch { Write-Host "Error getting IP configuration: $_" -ForegroundColor Red return $null } } function Analyze-NetworkAdapters { Write-Host "`nAnalyzing Network Adapters..." -ForegroundColor Yellow try { $adapters = Invoke-Command -ComputerName $global:targetComputer -ScriptBlock { Get-NetAdapter | Select-Object Name, InterfaceDescription, Status, LinkSpeed, MacAddress } $adapters | Format-Table -AutoSize return $adapters } catch { Write-Host "Error analyzing network adapters: $_" -ForegroundColor Red return $null } } function Check-DNSSettings { Write-Host "`nChecking DNS Settings..." -ForegroundColor Yellow try { $dnsSettings = Invoke-Command -ComputerName $global:targetComputer -ScriptBlock { Get-DnsClientServerAddress | Select-Object InterfaceAlias, ServerAddresses } $dnsSettings | Format-Table -AutoSize return $dnsSettings } catch { Write-Host "Error checking DNS settings: $_" -ForegroundColor Red return $null } } function Perform-NetworkConnectivityTests { Write-Host "`nPerforming Network Connectivity Tests..." -ForegroundColor Yellow try { $results = @() $testTargets = @("8.8.8.8", "www.google.com", $global:targetComputer) foreach ($target in $testTargets) { $pingResult = Test-Connection -ComputerName $target -Count 4 -ErrorAction SilentlyContinue $results += [PSCustomObject]@{ Target = $target Successful = if ($pingResult) { $true } else { $false } AverageResponseTime = if ($pingResult) { ($pingResult | Measure-Object -Property ResponseTime -Average).Average } else { "N/A" } } } $results | Format-Table -AutoSize return $results } catch { Write-Host "Error performing network connectivity tests: $_" -ForegroundColor Red return $null } } function View-RoutingTable { Write-Host "`nViewing Routing Table..." -ForegroundColor Yellow try { $routes = Invoke-Command -ComputerName $global:targetComputer -ScriptBlock { Get-NetRoute | Select-Object DestinationPrefix, NextHop, RouteMetric, InterfaceAlias } $routes | Format-Table -AutoSize return $routes } catch { Write-Host "Error viewing routing table: $_" -ForegroundColor Red return $null } } function Check-NetworkShares { Write-Host "`nChecking Network Shares..." -ForegroundColor Yellow try { $shares = Invoke-Command -ComputerName $global:targetComputer -ScriptBlock { Get-SmbShare | Select-Object Name, Path, Description } $shares | Format-Table -AutoSize return $shares } catch { Write-Host "Error checking network shares: $_" -ForegroundColor Red return $null } } function Analyze-OpenPorts { Write-Host "`nAnalyzing Open Ports..." -ForegroundColor Yellow try { $openPorts = Invoke-Command -ComputerName $global:targetComputer -ScriptBlock { Get-NetTCPConnection | Where-Object State -eq 'Listen' | Select-Object LocalAddress, LocalPort, State, OwningProcess } $openPorts | Format-Table -AutoSize return $openPorts } catch { Write-Host "Error analyzing open ports: $_" -ForegroundColor Red return $null } } function View-NetworkStatistics { Write-Host "`nViewing Network Statistics..." -ForegroundColor Yellow try { $stats = Invoke-Command -ComputerName $global:targetComputer -ScriptBlock { $tcpStats = Get-NetTCPConnection | Group-Object State | Select-Object Name, Count $ipStats = Get-NetIPv4Protocol | Select-Object DefaultHopLimit, NeighborCacheLimit, RouteCacheLimit return @{ TCPConnections = $tcpStats IPv4Stats = $ipStats } } $stats.TCPConnections | Format-Table -AutoSize $stats.IPv4Stats | Format-List return $stats } catch { Write-Host "Error viewing network statistics: $_" -ForegroundColor Red return $null } } function Generate-HTMLReport { param([hashtable]$AllResults) Write-Host "`nGenerating Comprehensive HTML Report..." -ForegroundColor Yellow $reportContent = @" <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>IP Configuration Analysis Report</title> <style> body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 1200px; margin: 0 auto; padding: 20px; } h1, h2, h3 { color: #0078D4; } table { border-collapse: collapse; width: 100%; margin-bottom: 20px; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } .warning { color: orange; } .critical { color: red; } </style> </head> <body> <h1>IP Configuration Analysis Report</h1> <p>Generated on: $(Get-Date)</p> <p>Target Computer: $global:targetComputer</p> <h2>IP Configuration</h2> $($AllResults.IPConfig | ConvertTo-Html -Fragment) <h2>Network Adapters</h2> $($AllResults.NetworkAdapters | ConvertTo-Html -Fragment) <h2>DNS Settings</h2> $($AllResults.DNSSettings | ConvertTo-Html -Fragment) <h2>Network Connectivity Tests</h2> $($AllResults.ConnectivityTests | ConvertTo-Html -Fragment) <h2>Routing Table</h2> $($AllResults.RoutingTable | ConvertTo-Html -Fragment) <h2>Network Shares</h2> $($AllResults.NetworkShares | ConvertTo-Html -Fragment) <h2>Open Ports</h2> $($AllResults.OpenPorts | ConvertTo-Html -Fragment) <h2>Network Statistics</h2> <h3>TCP Connections</h3> $($AllResults.NetworkStats.TCPConnections | ConvertTo-Html -Fragment) <h3>IPv4 Statistics</h3> $($AllResults.NetworkStats.IPV4Stats | ConvertTo-Html -Fragment) </body> </html> "@ $reportContent | Out-File -FilePath $global:reportPath Write-Host "Report generated and saved to: $global:reportPath" -ForegroundColor Green } # Main program loop $allResults = @{} do { Show-Menu $choice = Read-Host "`nEnter your choice (1-11)" switch ($choice) { "1" { Set-TargetComputer } "2" { $allResults.IPConfig = Get-IPConfiguration } "3" { $allResults.NetworkAdapters = Analyze-NetworkAdapters } "4" { $allResults.DNSSettings = Check-DNSSettings } "5" { $allResults.ConnectivityTests = Perform-NetworkConnectivityTests } "6" { $allResults.RoutingTable = View-RoutingTable } "7" { $allResults.NetworkShares = Check-NetworkShares } "8" { $allResults.OpenPorts = Analyze-OpenPorts } "9" { $allResults.NetworkStats = View-NetworkStatistics } "10" { Generate-HTMLReport -AllResults $allResults } "11" { Write-Host "Exiting program..." -ForegroundColor Yellow; break } default { Write-Host "Invalid choice. Please try again." -ForegroundColor Red } } if ($choice -ne "11") { Read-Host "`nPress Enter to continue..." } } while ($choice -ne "11")
This IP Configuration Toolkit includes:
- A menu-driven interface for easy navigation.
- Functions to analyze and manage various aspects of IP configurations:
- IP Configuration retrieval
- Network Adapter analysis
- DNS Settings check
- Network Connectivity Tests
- Routing Table view
- Network Shares check
- Open Ports analysis
- Network Statistics view
- Option to set a target computer (local or remote)
- HTML report generation for easy sharing and viewing of results
Key features:
- Comprehensive IP configuration information gathering
- Detailed analysis of network adapters
- DNS settings review
- Network connectivity tests to key targets
- Routing table examination
- Network shares enumeration
- Open ports analysis for security review
- Network statistics overview
This tool is particularly useful for:
- Network administrators troubleshooting IP configuration issues
- System administrators performing network health checks
- IT professionals analyzing network setups on remote systems
- Security analysts reviewing open ports and network configurations
To use this script effectively:
- Run PowerShell as an administrator
- Ensure you have the necessary permissions to query network information on the target computer
- For remote computer analysis, make sure you have appropriate network access and permissions
- Review the generated HTML report for a comprehensive overview of the IP configuration and network status
This script provides a thorough analysis of IP configurations and related network settings, helping to identify potential issues, misconfigurations, or areas that need attention. It’s designed to give administrators a quick but comprehensive view of a system’s network configuration and status.