Update ip-settings.ps1
This commit is contained in:
parent
2656e382cc
commit
95c220fdd7
|
|
@ -4,7 +4,7 @@ function Write-OK($msg) { Write-Host " [OK] $msg" -ForegroundColor Green }
|
|||
function Write-Info($msg) { Write-Host " [..] $msg" -ForegroundColor Yellow }
|
||||
function Write-Err($msg) { Write-Host " [!!] $msg" -ForegroundColor Red }
|
||||
|
||||
# Admin check - no line continuation
|
||||
# Admin check
|
||||
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$wp = New-Object Security.Principal.WindowsPrincipal($id)
|
||||
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator
|
||||
|
|
@ -63,9 +63,9 @@ Write-OK "Selected: $nicName (Index $nicIdx)"
|
|||
# STEP 3 - Choose profile
|
||||
Write-Host ""
|
||||
Write-Host " Profiles:" -ForegroundColor White
|
||||
Write-Host " [1] Camera Control -> 192.168.178.22 /24 GW: 192.168.178.1" -ForegroundColor White
|
||||
Write-Host " [2] LAN Profile 2 -> 192.168.1.222 /24 GW: 192.168.1.1" -ForegroundColor White
|
||||
Write-Host " [3] DHCP (automatic)" -ForegroundColor White
|
||||
Write-Host " [1] Camera Control -> 192.168.178.22 /24 GW: 192.168.178.1 DNS: 192.168.178.10 / 192.168.178.14" -ForegroundColor White
|
||||
Write-Host " [2] LAN Profile 2 -> 192.168.1.222 /24 GW: 192.168.1.1 DNS: Automatic" -ForegroundColor White
|
||||
Write-Host " [3] DHCP (automatic) DNS: Automatic" -ForegroundColor White
|
||||
Write-Host ""
|
||||
$profileChoice = Read-Host " Enter profile number"
|
||||
|
||||
|
|
@ -73,25 +73,45 @@ $profileChoice = Read-Host " Enter profile number"
|
|||
Write-Info "Applying settings..."
|
||||
|
||||
if ($profileChoice -eq "1") {
|
||||
$newIP = "192.168.178.22"; $prefix = 24; $gateway = "192.168.178.1"
|
||||
$newIP = "192.168.178.22"
|
||||
$prefix = 24
|
||||
$gateway = "192.168.178.1"
|
||||
$dns1 = "192.168.178.10"
|
||||
$dns2 = "192.168.178.14"
|
||||
|
||||
Remove-NetIPAddress -InterfaceIndex $nicIdx -Confirm:$false -ErrorAction SilentlyContinue
|
||||
Remove-NetRoute -InterfaceIndex $nicIdx -Confirm:$false -ErrorAction SilentlyContinue
|
||||
New-NetIPAddress -InterfaceIndex $nicIdx -IPAddress $newIP -PrefixLength $prefix -DefaultGateway $gateway | Out-Null
|
||||
Set-DnsClientServerAddress -InterfaceIndex $nicIdx -ServerAddresses $gateway | Out-Null
|
||||
Write-OK "Camera Control applied -> $newIP/$prefix GW: $gateway"
|
||||
Set-DnsClientServerAddress -InterfaceIndex $nicIdx -ServerAddresses ($dns1, $dns2) | Out-Null
|
||||
|
||||
Write-OK "Camera Control applied"
|
||||
Write-OK " IP : $newIP/$prefix"
|
||||
Write-OK " Gateway : $gateway"
|
||||
Write-OK " DNS 1 : $dns1"
|
||||
Write-OK " DNS 2 : $dns2"
|
||||
}
|
||||
elseif ($profileChoice -eq "2") {
|
||||
$newIP = "192.168.1.222"; $prefix = 24; $gateway = "192.168.1.1"
|
||||
$newIP = "192.168.1.222"
|
||||
$prefix = 24
|
||||
$gateway = "192.168.1.1"
|
||||
|
||||
Remove-NetIPAddress -InterfaceIndex $nicIdx -Confirm:$false -ErrorAction SilentlyContinue
|
||||
Remove-NetRoute -InterfaceIndex $nicIdx -Confirm:$false -ErrorAction SilentlyContinue
|
||||
New-NetIPAddress -InterfaceIndex $nicIdx -IPAddress $newIP -PrefixLength $prefix -DefaultGateway $gateway | Out-Null
|
||||
Set-DnsClientServerAddress -InterfaceIndex $nicIdx -ServerAddresses $gateway | Out-Null
|
||||
Write-OK "LAN Profile 2 applied -> $newIP/$prefix GW: $gateway"
|
||||
Set-DnsClientServerAddress -InterfaceIndex $nicIdx -ResetServerAddresses | Out-Null
|
||||
|
||||
Write-OK "LAN Profile 2 applied"
|
||||
Write-OK " IP : $newIP/$prefix"
|
||||
Write-OK " Gateway : $gateway"
|
||||
Write-OK " DNS : Automatic"
|
||||
}
|
||||
elseif ($profileChoice -eq "3") {
|
||||
Set-NetIPInterface -InterfaceIndex $nicIdx -Dhcp Enabled
|
||||
Set-DnsClientServerAddress -InterfaceIndex $nicIdx -ResetServerAddresses
|
||||
Write-OK "Adapter '$nicName' switched to DHCP."
|
||||
|
||||
Write-OK "Adapter '$nicName' switched to DHCP"
|
||||
Write-OK " IP : Automatic"
|
||||
Write-OK " DNS : Automatic"
|
||||
}
|
||||
else {
|
||||
Write-Err "Invalid profile choice. No changes made."
|
||||
|
|
@ -103,11 +123,16 @@ else {
|
|||
Write-Info "Verifying new config..."
|
||||
Start-Sleep -Seconds 2
|
||||
$verify = Get-NetIPAddress -InterfaceIndex $nicIdx -AddressFamily IPv4 -ErrorAction SilentlyContinue
|
||||
$dnsVerify = Get-DnsClientServerAddress -InterfaceIndex $nicIdx -AddressFamily IPv4 -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host ""
|
||||
if ($verify) {
|
||||
Write-Host ""
|
||||
Write-Host " Current IP : $($verify.IPAddress)/$($verify.PrefixLength)" -ForegroundColor Green
|
||||
Write-Host " IP : $($verify.IPAddress)/$($verify.PrefixLength)" -ForegroundColor Green
|
||||
}
|
||||
if ($dnsVerify -and $dnsVerify.ServerAddresses) {
|
||||
Write-Host " DNS : $($dnsVerify.ServerAddresses -join ' / ')" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Info "No IP yet (normal for DHCP)"
|
||||
Write-Host " DNS : Automatic" -ForegroundColor Green
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
|
|
|||
Loading…
Reference in a new issue