能力值:
( LV2,RANK:10 )
|
-
-
2 楼
学习一下
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
学习一下
|
能力值:
( LV6,RANK:80 )
|
-
-
4 楼
学习
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
66
|
能力值:
( LV3,RANK:30 )
|
-
-
6 楼
谢谢分享发 发
|
能力值:
( LV2,RANK:10 )
|
-
-
7 楼
学习学习
|
能力值:
( LV2,RANK:10 )
|
-
-
8 楼
谢谢分享
|
能力值:
( LV2,RANK:15 )
|
-
-
9 楼
# 以管理员身份运行此脚本 # 执行策略放行 Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force Clear-Host
# ===================== 可自定义静态参数 ===================== # IPv4 静态配置 $StaticIPv4Addr = "10.0.0.2" $StaticIPv4Prefix = 24 $StaticIPv4Gateway = "10.0.0.1" $StaticIPv4Dns1 = "114.114.114.114" $StaticIPv4Dns2 = "8.8.8.8"
# IPv6 静态配置 $StaticIPv6Addr = "2409:xxxx:xxxx:xxxx::2" $StaticIPv6Prefix = 64 $StaticIPv6Gateway = "2409:xxxx:xxxx:xxxx::1" $StaticIPv6Dns1 = "2400:da00::6666" $StaticIPv6Dns2 = "2001:4860:4860::8888"
# ===================== 获取活动网卡 ===================== $adapter = Get-NetAdapter | Where-Object { $_.Status -eq "Up" } | Select-Object -First 1 if (-not $adapter) { Write-Host "错误:未检测到活动的网络适配器!" -ForegroundColor Red pause exit } $ifIndex = $adapter.ifIndex $nicName = $adapter.Name
# ===================== 功能菜单 ===================== Write-Host "=============================================" -ForegroundColor Cyan Write-Host " 网络配置工具 (IPv4 + IPv6) " -ForegroundColor Cyan Write-Host " 当前网卡:$nicName 接口索引:$ifIndex" -ForegroundColor Cyan Write-Host "=============================================" -ForegroundColor Cyan Write-Host " 1. 切换为 DHCP 自动获取 (IPv4+IPv6)" Write-Host " 2. 手动配置静态 IP (IPv4+IPv6)" Write-Host "=============================================" -ForegroundColor Cyan $choice = Read-Host "请输入选项 [1/2]"
# ===================== 分支逻辑 ===================== switch ($choice) { "1" { Write-Host "`n正在切换为 DHCP 自动获取..." -ForegroundColor Yellow
# IPv4 开启DHCP、清空DNS Set-NetIPInterface -InterfaceIndex $ifIndex -AddressFamily IPv4 -Dhcp Enabled Set-DnsClientServerAddress -InterfaceIndex $ifIndex -ResetServerAddresses
# IPv6 开启DHCPv6、清空DNS Set-NetIPInterface -InterfaceIndex $ifIndex -AddressFamily IPv6 -Dhcp Enabled Set-DnsClientServerAddress -InterfaceIndex $ifIndex -ResetServerAddresses
Write-Host "`n✅ DHCP 配置完成!" -ForegroundColor Green }
"2" { Write-Host "`n正在配置静态 IPv4 + IPv6 ..." -ForegroundColor Yellow
# 先关闭DHCP,再配置静态IPv4 Set-NetIPInterface -InterfaceIndex $ifIndex -AddressFamily IPv4 -Dhcp Disabled New-NetIPAddress -InterfaceIndex $ifIndex -IPAddress $StaticIPv4Addr -PrefixLength $StaticIPv4Prefix -DefaultGateway $StaticIPv4Gateway -AddressFamily IPv4 | Out-Null Set-DnsClientServerAddress -InterfaceIndex $ifIndex -ServerAddresses $StaticIPv4Dns1, $StaticIPv4Dns2
# 配置静态IPv6 Set-NetIPInterface -InterfaceIndex $ifIndex -AddressFamily IPv6 -Dhcp Disabled New-NetIPAddress -InterfaceIndex $ifIndex -IPAddress $StaticIPv6Addr -PrefixLength $StaticIPv6Prefix -DefaultGateway $StaticIPv6Gateway -AddressFamily IPv6 | Out-Null Set-DnsClientServerAddress -InterfaceIndex $ifIndex -ServerAddresses $StaticIPv6Dns1, $StaticIPv6Dns2
Write-Host "`n✅ 静态IP配置完成!" -ForegroundColor Green Write-Host "---------------------------------------------" Write-Host "IPv4 地址: $StaticIPv4Addr/$StaticIPv4Prefix" Write-Host "IPv4 网关: $StaticIPv4Gateway" Write-Host "IPv4 DNS : $StaticIPv4Dns1 , $StaticIPv4Dns2" Write-Host "---------------------------------------------" Write-Host "IPv6 地址: $StaticIPv6Addr/$StaticIPv6Prefix" Write-Host "IPv6 网关: $StaticIPv6Gateway" Write-Host "IPv6 DNS : $StaticIPv6Dns1 , $StaticIPv6Dns2" }
default { Write-Host "`n❌ 输入无效,请重新运行脚本选择正确选项!" -ForegroundColor Red } }
# 展示最终网卡地址信息 Write-Host "`n---------------------------------------------" Write-Host "当前网卡地址详情:" -ForegroundColor Cyan Get-NetIPAddress -InterfaceIndex $ifIndex -AddressFamily IPv4 Get-NetIPAddress -InterfaceIndex $ifIndex -AddressFamily IPv6
Write-Host "`n按任意键退出..." pause
AI改的,支持IPV6和恢复DHCP配置
|
|
|