- Directorios: PascalCase (p2601_dasuten → P2601_Dasuten) - Planes: numeración pura (P2601_6.1.A → P2601.06.01) - Sin caracteres especiales en nombres de archivo - 07_proyectos.md: convención RFC-ADN-01 integrada, P2604/P2605 agregados - evento:listar: nueva opción --detalle para descripciones completas
400 lines
14 KiB
PowerShell
400 lines
14 KiB
PowerShell
# Script de diagnóstico de red local para pc-dasu0
|
|
# Uso: .\Diagnose-LocalNetwork.ps1 [-InterfaceAlias "Ethernet"] [-Detailed $true]
|
|
|
|
param(
|
|
[string]$InterfaceAlias = "Ethernet",
|
|
[bool]$Detailed = $true,
|
|
[string]$LogPath = "C:\Logs\NetworkDiagnostic"
|
|
)
|
|
|
|
# Configuración inicial
|
|
$ErrorActionPreference = "Stop"
|
|
$Timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
|
|
$LogFile = Join-Path $LogPath "NetworkDiagnostic_$Timestamp.log"
|
|
$ReportFile = Join-Path $LogPath "NetworkReport_$Timestamp.md"
|
|
|
|
# Crear directorio de logs si no existe
|
|
if (-not (Test-Path $LogPath)) {
|
|
New-Item -ItemType Directory -Path $LogPath -Force | Out-Null
|
|
}
|
|
|
|
# Funciones de logging
|
|
function Write-Log {
|
|
param([string]$Message, [string]$Level = "INFO")
|
|
|
|
$FormattedMessage = "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] [$Level] $Message"
|
|
|
|
switch ($Level) {
|
|
"ERROR" { Write-Host $FormattedMessage -ForegroundColor Red }
|
|
"WARNING" { Write-Host $FormattedMessage -ForegroundColor Yellow }
|
|
"SUCCESS" { Write-Host $FormattedMessage -ForegroundColor Green }
|
|
default { Write-Host $FormattedMessage -ForegroundColor Cyan }
|
|
}
|
|
|
|
$FormattedMessage | Out-File -FilePath $LogFile -Append
|
|
}
|
|
|
|
function Write-Report {
|
|
param([string]$Content)
|
|
$Content | Out-File -FilePath $ReportFile -Append
|
|
}
|
|
|
|
function Test-Command {
|
|
param([string]$Command)
|
|
try {
|
|
Get-Command $Command -ErrorAction Stop | Out-Null
|
|
return $true
|
|
} catch {
|
|
return $false
|
|
}
|
|
}
|
|
|
|
# Inicio del diagnóstico
|
|
Write-Log "========================================"
|
|
Write-Log " DIAGNÓSTICO DE RED LOCAL - pc-dasu0"
|
|
Write-Log "========================================"
|
|
Write-Log ""
|
|
|
|
Write-Report "# Reporte de Diagnóstico de Red Local"
|
|
Write-Report "Fecha: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
|
|
Write-Report "Hostname: $env:COMPUTERNAME"
|
|
Write-Report "Usuario: $env:USERNAME"
|
|
Write-Report ""
|
|
|
|
# 1. Verificar adaptador de red
|
|
Write-Log "1. Verificando adaptador de red '$InterfaceAlias'..."
|
|
Write-Report "## 1. Información del Adaptador de Red"
|
|
|
|
try {
|
|
$NetworkAdapter = Get-NetAdapter -Name $InterfaceAlias -ErrorAction Stop
|
|
|
|
Write-Log " Adaptador encontrado: $($NetworkAdapter.Name)"
|
|
Write-Log " Estado: $($NetworkAdapter.Status)"
|
|
Write-Log " Velocidad: $($NetworkAdapter.LinkSpeed)"
|
|
|
|
Write-Report "### Adaptador: $($NetworkAdapter.Name)"
|
|
Write-Report "- Estado: $($NetworkAdapter.Status)"
|
|
Write-Report "- Velocidad: $($NetworkAdapter.LinkSpeed)"
|
|
Write-Report "- MAC Address: $($NetworkAdapter.MacAddress)"
|
|
Write-Report "- Interface Description: $($NetworkAdapter.InterfaceDescription)"
|
|
Write-Report ""
|
|
|
|
if ($NetworkAdapter.Status -ne "Up") {
|
|
Write-Log " ADVERTENCIA: El adaptador no está activo" -Level "WARNING"
|
|
}
|
|
|
|
} catch {
|
|
Write-Log " ERROR: No se encontró el adaptador '$InterfaceAlias'" -Level "ERROR"
|
|
Write-Log " Adaptadores disponibles:"
|
|
Get-NetAdapter | ForEach-Object {
|
|
Write-Log " - $($_.Name): $($_.Status)"
|
|
}
|
|
Write-Report "ERROR: Adaptador '$InterfaceAlias' no encontrado"
|
|
exit 1
|
|
}
|
|
|
|
# 2. Obtener configuración IP
|
|
Write-Log "2. Obteniendo configuración IP..."
|
|
Write-Report "## 2. Configuración IP"
|
|
|
|
try {
|
|
$IPConfiguration = Get-NetIPConfiguration -InterfaceAlias $InterfaceAlias -ErrorAction Stop
|
|
|
|
Write-Log " IPv4 Address: $($IPConfiguration.IPv4Address.IPAddress)"
|
|
Write-Log " Subnet Mask: $($IPConfiguration.IPv4Address.PrefixLength)"
|
|
Write-Log " Gateway: $($IPConfiguration.IPv4DefaultGateway.NextHop)"
|
|
|
|
Write-Report "### Configuración IPv4"
|
|
Write-Report "- Dirección IP: $($IPConfiguration.IPv4Address.IPAddress)"
|
|
Write-Report "- Prefijo: /$($IPConfiguration.IPv4Address.PrefixLength)"
|
|
Write-Report "- Gateway: $($IPConfiguration.IPv4DefaultGateway.NextHop)"
|
|
Write-Report ""
|
|
|
|
# Calcular subred
|
|
$IPAddress = $IPConfiguration.IPv4Address.IPAddress
|
|
$PrefixLength = $IPConfiguration.IPv4Address.PrefixLength
|
|
$SubnetMask = [System.Net.IPAddress]::Parse(([System.Net.IPAddress]::Parse("255.255.255.255").GetAddressBytes() |
|
|
ForEach-Object { $_ -shl (32 - $PrefixLength) }))
|
|
|
|
$NetworkAddress = [System.Net.IPAddress]::new((
|
|
[System.Net.IPAddress]::Parse($IPAddress).GetAddressBytes() |
|
|
ForEach-Object { $_ -band $SubnetMask.GetAddressBytes()[$i]; $i++ }))
|
|
|
|
$Subnet = "$NetworkAddress/$PrefixLength"
|
|
Write-Log " Subred calculada: $Subnet"
|
|
Write-Report "- Subred: $Subnet"
|
|
Write-Report ""
|
|
|
|
# Servidores DNS
|
|
Write-Log " Servidores DNS:"
|
|
$DNSServers = $IPConfiguration.DNSServer.ServerAddresses
|
|
if ($DNSServers) {
|
|
$i = 1
|
|
foreach ($DNS in $DNSServers) {
|
|
Write-Log " $i. $DNS"
|
|
Write-Report "- DNS $($i): $DNS"
|
|
$i++
|
|
}
|
|
} else {
|
|
Write-Log " ADVERTENCIA: No hay servidores DNS configurados" -Level "WARNING"
|
|
Write-Report "- DNS: No configurado"
|
|
}
|
|
|
|
Write-Report ""
|
|
|
|
} catch {
|
|
Write-Log " ERROR: No se pudo obtener configuración IP" -Level "ERROR"
|
|
Write-Report "ERROR: No se pudo obtener configuración IP"
|
|
}
|
|
|
|
# 3. Probar conectividad
|
|
Write-Log "3. Probando conectividad de red..."
|
|
Write-Report "## 3. Pruebas de Conectividad"
|
|
|
|
# Gateway
|
|
$Gateway = $IPConfiguration.IPv4DefaultGateway.NextHop
|
|
if ($Gateway) {
|
|
Write-Log " Probando gateway $Gateway..."
|
|
$GatewayTest = Test-NetConnection -ComputerName $Gateway -InformationLevel Quiet
|
|
|
|
if ($GatewayTest) {
|
|
Write-Log " ✅ Gateway alcanzable" -Level "SUCCESS"
|
|
Write-Report "- Gateway ($Gateway): ✅ Alcanzable"
|
|
} else {
|
|
Write-Log " ❌ Gateway no alcanzable" -Level "ERROR"
|
|
Write-Report "- Gateway ($Gateway): ❌ No alcanzable"
|
|
}
|
|
} else {
|
|
Write-Log " ADVERTENCIA: No hay gateway configurado" -Level "WARNING"
|
|
Write-Report "- Gateway: No configurado"
|
|
}
|
|
|
|
# Internet
|
|
Write-Log " Probando conectividad a internet (8.8.8.8)..."
|
|
$InternetTest = Test-NetConnection -ComputerName "8.8.8.8" -InformationLevel Quiet -WarningAction SilentlyContinue
|
|
|
|
if ($InternetTest) {
|
|
Write-Log " ✅ Internet alcanzable" -Level "SUCCESS"
|
|
Write-Report "- Internet (8.8.8.8): ✅ Alcanzable"
|
|
} else {
|
|
Write-Log " ❌ Internet no alcanzable" -Level "ERROR"
|
|
Write-Report "- Internet (8.8.8.8): ❌ No alcanzable"
|
|
}
|
|
|
|
# srv-dasu (si se conoce la IP)
|
|
Write-Log " Probando conectividad a srv-dasu (192.168.1.205)..."
|
|
$SrvDasuTest = Test-NetConnection -ComputerName "192.168.1.205" -InformationLevel Quiet -WarningAction SilentlyContinue
|
|
|
|
if ($SrvDasuTest) {
|
|
Write-Log " ✅ srv-dasu alcanzable localmente" -Level "SUCCESS"
|
|
Write-Report "- srv-dasu (192.168.1.205): ✅ Alcanzable"
|
|
} else {
|
|
Write-Log " ⚠️ srv-dasu no alcanzable localmente" -Level "WARNING"
|
|
Write-Report "- srv-dasu (192.168.1.205): ⚠️ No alcanzable"
|
|
}
|
|
|
|
Write-Report ""
|
|
|
|
# 4. Verificar DNS
|
|
Write-Log "4. Verificando resolución DNS..."
|
|
Write-Report "## 4. Pruebas de DNS"
|
|
|
|
# Resolución de dominio DASUTEN
|
|
Write-Log " Probando resolución de dc-dasuten.dasuten.utnlr..."
|
|
try {
|
|
$DNSResult = Resolve-DnsName -Name "dc-dasuten.dasuten.utnlr" -ErrorAction Stop
|
|
|
|
if ($DNSResult.IPAddress) {
|
|
Write-Log " ✅ DNS resuelve a: $($DNSResult.IPAddress)" -Level "SUCCESS"
|
|
Write-Report "- dc-dasuten.dasuten.utnlr: ✅ $($DNSResult.IPAddress)"
|
|
} else {
|
|
Write-Log " ❌ DNS no devolvió IP" -Level "ERROR"
|
|
Write-Report "- dc-dasuten.dasuten.utnlr: ❌ Sin respuesta"
|
|
}
|
|
} catch {
|
|
Write-Log " ❌ Error en resolución DNS: $_" -Level "ERROR"
|
|
Write-Report "- dc-dasuten.dasuten.utnlr: ❌ Error: $_"
|
|
}
|
|
|
|
# Resolución inversa
|
|
Write-Log " Probando resolución inversa de 10.0.100.10..."
|
|
try {
|
|
$ReverseDNS = Resolve-DnsName -Name "10.0.100.10" -Type PTR -ErrorAction Stop
|
|
|
|
if ($ReverseDNS.NameHost) {
|
|
Write-Log " ✅ Resolución inversa: $($ReverseDNS.NameHost)" -Level "SUCCESS"
|
|
Write-Report "- 10.0.100.10 (PTR): ✅ $($ReverseDNS.NameHost)"
|
|
}
|
|
} catch {
|
|
Write-Log " ⚠️ No se pudo resolver PTR para 10.0.100.10" -Level "WARNING"
|
|
Write-Report "- 10.0.100.10 (PTR): ⚠️ No resuelto"
|
|
}
|
|
|
|
Write-Report ""
|
|
|
|
# 5. Verificar puertos críticos del dominio
|
|
Write-Log "5. Verificando puertos críticos del dominio..."
|
|
Write-Report "## 5. Puertos del Dominio DASUTEN"
|
|
|
|
$DomainController = "10.0.100.10"
|
|
$CriticalPorts = @(
|
|
@{Port=389; Service="LDAP"},
|
|
@{Port=88; Service="Kerberos"},
|
|
@{Port=445; Service="SMB"},
|
|
@{Port=53; Service="DNS"},
|
|
@{Port=135; Service="RPC"},
|
|
@{Port=636; Service="LDAPS"}
|
|
)
|
|
|
|
foreach ($PortInfo in $CriticalPorts) {
|
|
Write-Log " Probando puerto $($PortInfo.Port) ($($PortInfo.Service))..."
|
|
|
|
$PortTest = Test-NetConnection -ComputerName $DomainController -Port $PortInfo.Port -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
|
|
|
|
if ($PortTest.TcpTestSucceeded) {
|
|
Write-Log " ✅ Puerto $($PortInfo.Port) abierto" -Level "SUCCESS"
|
|
Write-Report "- $($PortInfo.Service) (puerto $($PortInfo.Port)): ✅ Abierto"
|
|
} else {
|
|
Write-Log " ❌ Puerto $($PortInfo.Port) cerrado" -Level "ERROR"
|
|
Write-Report "- $($PortInfo.Service) (puerto $($PortInfo.Port)): ❌ Cerrado"
|
|
}
|
|
}
|
|
|
|
Write-Report ""
|
|
|
|
# 6. Verificar Tailscale
|
|
Write-Log "6. Verificando estado de Tailscale..."
|
|
Write-Report "## 6. Estado de Tailscale"
|
|
|
|
if (Test-Command "tailscale") {
|
|
try {
|
|
$TailscaleStatus = & tailscale status --json 2>$null | ConvertFrom-Json
|
|
|
|
if ($TailscaleStatus.Self.TailscaleIPs) {
|
|
$TailscaleIP = $TailscaleStatus.Self.TailscaleIPs[0]
|
|
Write-Log " ✅ Tailscale conectado: $TailscaleIP" -Level "SUCCESS"
|
|
Write-Report "- Estado: ✅ Conectado"
|
|
Write-Report "- IP Tailscale: $TailscaleIP"
|
|
|
|
# Verificar peers
|
|
$PeerCount = ($TailscaleStatus.Peer | Measure-Object).Count
|
|
Write-Log " Peers conectados: $PeerCount"
|
|
Write-Report "- Peers conectados: $PeerCount"
|
|
} else {
|
|
Write-Log " ⚠️ Tailscale instalado pero no conectado" -Level "WARNING"
|
|
Write-Report "- Estado: ⚠️ Instalado pero no conectado"
|
|
}
|
|
} catch {
|
|
Write-Log " ⚠️ No se pudo obtener estado de Tailscale" -Level "WARNING"
|
|
Write-Report "- Estado: ⚠️ Error al obtener estado"
|
|
}
|
|
} else {
|
|
Write-Log " ⚠️ Tailscale no está instalado" -Level "WARNING"
|
|
Write-Report "- Estado: ⚠️ No instalado"
|
|
}
|
|
|
|
Write-Report ""
|
|
|
|
# 7. Escanear red local (opcional)
|
|
if ($Detailed) {
|
|
Write-Log "7. Escaneando dispositivos en red local..."
|
|
Write-Report "## 7. Dispositivos en Red Local"
|
|
|
|
try {
|
|
# Usar ARP para detectar dispositivos
|
|
$ARPTable = arp -a | Select-String "dynamic" | ForEach-Object {
|
|
$Line = $_.ToString().Trim()
|
|
$Parts = $Line -split '\s+'
|
|
|
|
[PSCustomObject]@{
|
|
IP = $Parts[0]
|
|
MAC = $Parts[1]
|
|
Type = $Parts[2]
|
|
}
|
|
}
|
|
|
|
$DeviceCount = ($ARPTable | Measure-Object).Count
|
|
Write-Log " Dispositivos detectados en ARP: $DeviceCount"
|
|
Write-Report "- Dispositivos en tabla ARP: $DeviceCount"
|
|
|
|
if ($DeviceCount -gt 0) {
|
|
Write-Report ""
|
|
Write-Report "### Primeros 10 dispositivos:"
|
|
$ARPTable | Select-Object -First 10 | ForEach-Object {
|
|
Write-Report "- $($_.IP) ($($_.MAC))"
|
|
}
|
|
}
|
|
|
|
} catch {
|
|
Write-Log " ⚠️ No se pudo escanear red local" -Level "WARNING"
|
|
Write-Report "- Escaneo: ⚠️ No disponible"
|
|
}
|
|
|
|
Write-Report ""
|
|
}
|
|
|
|
# 8. Generar recomendaciones
|
|
Write-Log "8. Generando recomendaciones..."
|
|
Write-Report "## 8. Recomendaciones para Comunicación Local"
|
|
|
|
$BaseNetwork = $IPAddress -replace '\.\d+$', ''
|
|
$RecommendedSrvIP = "$BaseNetwork.205"
|
|
$RecommendedPcIP = "$BaseNetwork.100"
|
|
|
|
Write-Report "### Configuración recomendada para comunicación local:"
|
|
Write-Report ""
|
|
Write-Report "1. **IPs estáticas locales:**"
|
|
Write-Report " - srv-dasu: $RecommendedSrvIP/24"
|
|
Write-Report " - pc-dasu0: $RecommendedPcIP/24"
|
|
Write-Report ""
|
|
Write-Report "2. **Configuración de red en pc-dasu0:**"
|
|
Write-Report " - IP: $RecommendedPcIP"
|
|
Write-Report " - Máscara: 255.255.255.0"
|
|
Write-Report " - Gateway: $Gateway"
|
|
Write-Report " - DNS Primario: 10.0.100.10 (dc-dasuten)"
|
|
Write-Report " - DNS Secundario: 8.8.8.8"
|
|
Write-Report " - Suffix DNS: dasuten.utnlr"
|
|
Write-Report ""
|
|
Write-Report "3. **Verificaciones previas:**"
|
|
Write-Report " - Confirmar que $RecommendedSrvIP y $RecommendedPcIP no están en uso"
|
|
Write-Report " - Verificar firewall (permitir ICMP, puertos 389, 88, 445, 53)"
|
|
Write-Report " - Mantener Tailscale activo como respaldo"
|
|
Write-Report ""
|
|
Write-Report "4. **Comandos de prueba post-configuración:**"
|
|
Write-Report " ```powershell"
|
|
Write-Report " # Probar conectividad local"
|
|
Write-Report " Test-NetConnection $RecommendedSrvIP"
|
|
Write-Report " "
|
|
Write-Report " # Probar resolución DNS"
|
|
Write-Report " Resolve-DnsName dc-dasuten.dasuten.utnlr"
|
|
Write-Report " "
|
|
Write-Report " # Probar puertos del dominio"
|
|
Write-Report " Test-NetConnection 10.0.100.10 -Port 389"
|
|
Write-Report " ```"
|
|
Write-Report ""
|
|
|
|
# 9. Resumen final
|
|
Write-Log "9. Generando resumen final..."
|
|
Write-Report "## 9. Resumen del Diagnóstico"
|
|
|
|
Write-Report "- **Adaptador de red**: $($NetworkAdapter.Name) ($($NetworkAdapter.Status))"
|
|
Write-Report "- **IP Configurada**: $IPAddress/$PrefixLength"
|
|
Write-Report "- **Gateway**: $(if($Gateway) {$Gateway} else {"No configurado"})"
|
|
Write-Report "- **Subred**: $Subnet"
|
|
Write-Report "- **DNS Servers**: $(if($DNSServers) {$DNSServers -join ', '} else {"No configurado"})"
|
|
Write-Report "- **Internet**: $(if($InternetTest) {"✅ Alcanzable"} else {"❌ No alcanzable"})"
|
|
Write-Report "- **srv-dasu local**: $(if($SrvDasuTest) {"✅ Alcanzable"} else {"⚠️ No alcanzable"})"
|
|
Write-Report "- **Tailscale**: $(if(Test-Command "tailscale") {"✅ Instalado"} else {"⚠️ No instalado"})"
|
|
Write-Report ""
|
|
Write-Report "### Archivos generados:"
|
|
Write-Report "- Log detallado: $LogFile"
|
|
Write-Report "- Reporte completo: $ReportFile"
|
|
Write-Report ""
|
|
Write-Report "### Próximos pasos:"
|
|
Write-Report "1. Si la conectividad local falla, verificar configuración del router ISP"
|
|
Write-Report "2. Configurar IPs estáticas según recomendaciones"
|
|
Write-Report "3. Probar AD-Join después de configurar comunicación local"
|
|
Write-Report "4. Mantener Tailscale como respaldo para acceso remoto"
|
|
Write-Report ""
|
|
Write-Report "*Diagnóstico completado: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')*"
|