Advertisement
UnLovedCookie

Network.ps1

Mar 31st, 2025 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # irm ln.run/cookie | iex
  2. # https://discord.gg/dptDHp9p9k
  3. # https://github.com/UnLovedCookie/Network
  4.  
  5. $ErrorActionPreference = "SilentlyContinue"
  6.  
  7. # Self-elevate if not already admin
  8. if(-not([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){
  9.     Start-Process PowerShell -ArgumentList "-ExecutionPolicy Bypass", "-Command Set-Location '$PWD'; & '$PSCommandPath'" -Verb RunAs
  10.     exit
  11. }
  12.  
  13. # Functions
  14. function Set-NICProperty {
  15.     param([string]$Keyword, [string]$Value)
  16.     Get-NetAdapterAdvancedProperty -RegistryKeyword "*$Keyword" |
  17.     ForEach-Object { Set-NetAdapterAdvancedProperty -RegistryKeyword $_.RegistryKeyword -RegistryValue $Value -NoRestart }
  18. }
  19.  
  20. function Set-TCPSetting {
  21.     param([string]$Setting, [int]$Value)
  22.     Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -Name $Setting -Value $Value -Type DWord
  23.     Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" -Name $Setting -Value $Value -Type DWord
  24. }
  25.  
  26. # User Input
  27. Write-Host "Connection Type:`n[1] Fiber (100+ mbps)`n[2] VDSL (20-100 mbps)`n[3] ADSL (20< mbps)"
  28. $ConnectionType = [int](Read-Host "Choose (1-3)")
  29.  
  30. Write-Host "Optimize For:`n[1] Throughput (Speed)`n[2] Latency (Ping)"
  31. $OptimizeFor = [int](Read-Host "Choose (1-2)")
  32.  
  33. # Reset Advanced Network Adapter Options
  34. Get-NetAdapter | Where-Object { $_.Status -eq 'Up' } | Reset-NetAdapterAdvancedProperty -DisplayName '*' -NoRestart
  35. Write-Host "Reset Advanced Network Adapter Options"
  36.  
  37. # Reset TCP/IP Settings
  38. @(
  39.     "netsh int tcp reset",
  40.     "netsh winhttp reset proxy",
  41.     "netsh winsock reset",
  42.     "netsh int ip reset",
  43.     "netsh int ipv4 reset",
  44.     "netsh int ipv6 reset"
  45. ) | ForEach-Object { Invoke-Expression $_ *>$null }
  46. Write-Host "Reset TCP/IP Settings"
  47.  
  48. # Optimize Time To Live (TTL)
  49. $DefaultTTL = switch ($ConnectionType) {
  50.     1 { 255 }
  51.     2 { 128 }
  52.     3 { 64 }
  53.     default { 128 }
  54. }
  55. Set-TCPSetting "DefaultTTL" $DefaultTTL
  56. netsh int ipv4 set glob defaultcurhoplimit=$DefaultTTL | Out-Null
  57. netsh int ipv6 set glob defaultcurhoplimit=$DefaultTTL | Out-Null
  58. Write-Host "Set Time To Live (TTL) To $DefaultTTL"
  59.  
  60. # MTU Optimization
  61. $connectedInterfaces = netsh int show int | Select-String -Pattern "connected"
  62. foreach ($interface in $connectedInterfaces) {
  63.     $interfaceName = $interface -replace '.*\s{2,}', ''
  64.     netsh interface ipv4 set subinterface "$interfaceName" mtu=1500 store=persistent *>$null
  65. }
  66.  
  67. $mtu = 1501
  68. do {
  69.     $mtu--
  70.     $ping = ping google.com -f -n 1 -4 -l $mtu
  71.     $fragmented = $ping -match "fragmented"
  72. } while ($fragmented)
  73.  
  74. # Double check to make sure
  75. $ping = ping google.com -f -n 3 -4 -l $mtu
  76. $fragmented = $ping -match "fragmented"
  77. if ($fragmented) {
  78.     do {
  79.         $mtu--
  80.         $ping = ping google.com -f -n 1 -4 -l $mtu
  81.         $fragmented = $ping -match "fragmented"
  82.     } while ($fragmented)
  83. }
  84.  
  85. if ($mtu -ge 1472) { $mtu = 1500 }
  86.  
  87. foreach ($interface in $connectedInterfaces) {
  88.     $interfaceName = $interface -replace '.*\s{2,}', ''
  89.     netsh interface ipv4 set subinterface "$interfaceName" mtu=$mtu store=persistent *>$null
  90. }
  91. Write-Host "Set IPv4 MTU To $mtu"
  92.  
  93. # Disable Jumbo Packets
  94. Set-NICProperty "JumboPacket" "1514"
  95. Write-Host "Disable Jumbo Packets"
  96.  
  97. # Large Send Offload (LSO)
  98. if ($OptimizeFor -eq 1) {
  99.     Set-NICProperty "LsoV1IPv4" "1"
  100.     Set-NICProperty "LsoV2IPv4" "1"
  101.     Set-NICProperty "LsoV2IPv6" "1"
  102.     Write-Host "Enable Large Send Offload (LSO)"
  103. } else {
  104.     Set-NICProperty "LsoV1IPv4" "0"
  105.     Set-NICProperty "LsoV2IPv4" "0"
  106.     Set-NICProperty "LsoV2IPv6" "0"
  107.     Write-Host "Disable Large Send Offload (LSO)"
  108. }
  109.  
  110. # Set Fast Send Datagram
  111. Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\AFD\Parameters" -Name "FastSendDatagramThreshold" -Value $MTU -Type DWord
  112. Write-Host "Set Fast Send Datagram To $MTU"
  113.  
  114. # Disable Large MTU
  115. Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters" -Name "DisableLargeMTU" -Value 0 -Type DWord
  116. Write-Host "Disable Large MTU"
  117.  
  118. # Enable Path Maximum Transfer Unit (PMTU)
  119. Set-TCPSetting "EnablePMTUDiscovery" 1
  120. Write-Host "Enable Path Maximum Transfer Unit (PMTU)"
  121.  
  122. # Enable Path Maximum Transfer Unit (PMTU) Black Hole Detection
  123. Set-TCPSetting "EnablePMTUBHDetect" 1
  124. Write-Host "Enable Path Maximum Transfer Unit (PMTU) Black Hole Detection"
  125.  
  126. # Disable Window Scaling Heuristics
  127. Set-NetTCPSetting -ScalingHeuristics Disabled
  128. Write-Host "Disable Window Scaling Heuristics"
  129.  
  130. # Enable TCP Window Scaling, Disable TCP 1323 Timestamps
  131. Set-NetTCPSetting -Timestamps Disabled
  132. Set-TCPSetting "Tcp1323Opts" 1
  133. Write-Host "Enable TCP Window Scaling"
  134. Write-Host "Disable TCP 1323 Timestamps"
  135.  
  136. # Set Default TCP Window Size
  137. Set-TCPSetting "GlobalMaxTcpWindowSize" 65536
  138. Set-TCPSetting "TcpWindowSize" 65536
  139. Write-Host "Set Default TCP Window Size"
  140.  
  141. # Configure Autotuning
  142. if ($OptimizeFor -eq 1) {
  143.     Set-NetTCPSetting -AutoTuningLevelLocal normal
  144.     Write-Host "Enable Autotuning"
  145. } else {
  146.     Set-NetTCPSetting -AutoTuningLevelLocal highlyrestricted
  147.     Write-Host "Enable Highly Restricted Autotuning"
  148. }
  149.  
  150. # Enable Winsock/HTTP Autotuning
  151. netsh winsock set autotuning on | Out-Null
  152. $httpSettings = @(
  153.     @{Path="HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp"; Name="TcpAutotuning"},
  154.     @{Path="HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"; Name="TcpAutotuning"}
  155. )
  156. foreach ($setting in $httpSettings) {
  157.     Set-ItemProperty -Path $setting.Path -Name $setting.Name -Value 1 -Type DWord
  158. }
  159. Write-Host "Enable Winsock/HTTP Autotuning"
  160.  
  161. # Optimize RSS
  162. Set-NetOffloadGlobalSetting -ReceiveSideScaling Enabled
  163. $MaxRssProc = [Environment]::ProcessorCount - 2
  164. if ($MaxRssProc -lt 1) { $MaxRssProc = 1 }
  165. Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Ndis\Parameters" -Name "RssBaseCpu" -Value 1 -Type DWord
  166.  
  167. # Enable RSS
  168. $rssSettings = @(
  169.     @{Keyword="RSS"; Value="1"},
  170.     @{Keyword="NumRssQueues"; Value="4"},
  171.     @{Keyword="RSSProfile"; Value="4"},
  172.     @{Keyword="NumaNodeId"; Value="0"},
  173.     @{Keyword="RssBaseProcGroup"; Value="0"},
  174.     @{Keyword="RssMaxProcGroup"; Value="0"},
  175.     @{Keyword="RssBaseProcNumber"; Value="0"},
  176.     @{Keyword="RssMaxProcNumber"; Value="$MaxRssProc"},
  177.     @{Keyword="MaxRssProcessors"; Value="$MaxRssProc"},
  178.     @{Keyword="RssV2"; Value="1"},
  179.     @{Keyword="ValidateRssV2"; Value="1"}
  180. )
  181. foreach ($setting in $rssSettings) {
  182.     Set-NICProperty $setting.Keyword $setting.Value
  183. }
  184. Write-Host "Optimize RSS"
  185.  
  186. # Enable Network Task Offloading
  187. netsh int ipv4 set global taskoffload=enabled | Out-Null
  188. netsh int ipv6 set global taskoffload=enabled | Out-Null
  189. Set-TCPSetting "DisableTaskOffload" 0
  190. Write-Host "Enable Network Task Offloading"
  191.  
  192. # Disable TCP Chimney Offload
  193. Set-NetOffloadGlobalSetting -Chimney Disabled
  194. Write-Host "TCP Chimney Offload"
  195.  
  196. # Disable IPsec Offload
  197. Disable-NetAdapterIPsecOffload -Name *
  198. Set-NICProperty "IPsecOffloadV1IPv4" "0"
  199. Set-NICProperty "IPsecOffloadV2" "0"
  200. Set-NICProperty "IPsecOffloadV2IPv4" "0"
  201. Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\Ipsec" -Name "EnabledOffload" -Value 0 -Type DWord
  202. Write-Host "Disable IPsec Offload"
  203.  
  204. # Enable UDP and TCP Checksums
  205. Enable-NetAdapterChecksumOffload -Name *
  206. $checksumSettings = @(
  207.     @{Keyword="TCPUDPChecksumOffloadIPv4"; Value="3"},
  208.     @{Keyword="TCPUDPChecksumOffloadIPv6"; Value="3"},
  209.     @{Keyword="UDPChecksumOffloadIPv4"; Value="3"},
  210.     @{Keyword="UDPChecksumOffloadIPv6"; Value="3"},
  211.     @{Keyword="TCPChecksumOffloadIPv4"; Value="3"},
  212.     @{Keyword="TCPChecksumOffloadIPv6"; Value="3"},
  213.     @{Keyword="IPChecksumOffloadIPv4"; Value="3"}
  214. )
  215. foreach ($setting in $checksumSettings) {
  216.     Set-NICProperty $setting.Keyword $setting.Value
  217. }
  218. Write-Host "Enable UDP and TCP Checksums"
  219.  
  220. # Enable Address Resolution Protocol (ARP) Offload
  221. Set-NICProperty "PMARPOffload" "1"
  222. Write-Host "Enable Address Resolution Protocol (ARP) Offload"
  223.  
  224. # Delete Address Resolution Protocol (ARP) Cache
  225. netsh int ip delete arpcache | Out-Null
  226. Write-Host "Delete Address Resolution Protocol (ARP) Cache"
  227.  
  228. # Increase Address Resolution Protocol (ARP) Cache Size To 4096
  229. netsh int ipv4 set global neighborcachelimit=4096 | Out-Null
  230. netsh int ipv6 set global neighborcachelimit=4096 | Out-Null
  231. Write-Host "Increase Address Resolution Protocol (ARP) Cache Size to 4096"
  232.  
  233. # Disable Direct Memory Access (DMA) Coalescing
  234. Set-NICProperty "DMACoalescing" "0"
  235. Write-Host "Disable Direct Memory Access (DMA) Coalescing"
  236.  
  237. # Disable Receive Segment Coalescing State (RSC)
  238. Set-NICProperty "RscIPv4" "0"
  239. Set-NICProperty "RscIPv6" "0"
  240. Disable-NetAdapterRsc -Name *
  241. Write-Host "Disable Receive Segment Coalescing State (RSC)"
  242.  
  243. # Disable Packet Coalescing
  244. Set-NetOffloadGlobalSetting -PacketCoalescingFilter Disabled
  245. Write-Host "Disable Packet Coalescing"
  246.  
  247. # Enable Explicit Congestion Notification (ECN)
  248. netsh int tcp set global ecn=enabled | Out-Null
  249. Set-NetTCPSetting -EcnCapability Enabled
  250. Write-Host "Enable Explicit Congestion Notification (ECN)"
  251.  
  252. # Set Congestion Provider To BBR2/CTCP
  253. $osInfo = Get-WmiObject -Class Win32_OperatingSystem
  254. if ($osInfo.Caption -match "Windows 11") {
  255.     netsh int tcp set supplemental Internet CongestionProvider=bbr2 | Out-Null
  256.     Write-Host "Set Congestion Provider To BBR2"
  257. } else {
  258.     netsh int tcp set supplemental Internet CongestionProvider=CTCP | Out-Null
  259.     Write-Host "Set Congestion Provider To CTCP"
  260. }
  261.  
  262. # Increase the TCP Initial Congestion Window
  263. netsh int tcp set supplemental Internet icw=10 | Out-Null
  264. Write-Host "Increase the TCP Initial Congestion Window"
  265.  
  266. # Enable SMBv2 / SMBv3
  267. Set-SmbServerConfiguration -EnableSMB2Protocol $true -Confirm:$false
  268. Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters" -Name "SMB2" -Value 1 -Type DWord
  269. Write-Host "Enable SMBv2 / SMBv3"
  270.  
  271. # Enable Large System Cache
  272. $cacheSettings = @(
  273.     @{Path="HKLM:\System\CurrentControlSet\Control\Session Manager\Memory Management"; Name="LargeSystemCache"; Value=1},
  274.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters"; Name="Size"; Value=3}
  275. )
  276. foreach ($setting in $cacheSettings) {
  277.     Set-ItemProperty -Path $setting.Path -Name $setting.Name -Value $setting.Value -Type DWord
  278. }
  279. Write-Host "Enable Large System Cache"
  280.  
  281. # Optimize SMB Parameters
  282. $smbParams = @(
  283.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters"; Name="IRPStackSize"; Value=50},
  284.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters"; Name="RequireSecuritySignature"; Value=0},
  285.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters"; Name="SizReqBuf"; Value=17424},
  286.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters"; Name="MaxCmds"; Value=10},
  287.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters"; Name="MaxMpxCt"; Value=10},
  288.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters"; Name="MaxWorkItems"; Value=512},
  289.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters"; Name="MinFreeConnections"; Value=4},
  290.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanServer\Parameters"; Name="MaxFreeConnections"; Value=8},
  291.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanWorkstation\Parameters"; Name="MaxThreads"; Value=30},
  292.     @{Path="HKLM:\System\CurrentControlSet\Services\LanmanWorkstation\Parameters"; Name="MaxCollectionCount"; Value=32}
  293. )
  294. foreach ($param in $smbParams) {
  295.     Set-ItemProperty -Path $param.Path -Name $param.Name -Value $param.Value -Type DWord
  296. }
  297. Write-Host "Optimize SMB Parameters"
  298.  
  299. # Disable Memory Pressure Protection (MPP)
  300. Set-NetTCPSetting -MemoryPressureProtection Disabled
  301. Set-TCPSetting "EnableMPP" 0
  302. Write-Host "Disable Memory Pressure Protection (MPP)"
  303.  
  304. # Disable NetBIOS Over TCP/IP
  305. Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\NetBT\Parameters\Interfaces" -Name "NetBiosOptions" -Value 2 -Type DWord
  306. (Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled=True").SetTcpipNetbios(2) | Out-Null
  307. Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\NetBT\Parameters" -Name "NodeType" -Value 2 -Type DWord
  308. Write-Host "Disable NetBIOS Over TCP/IP"
  309.  
  310. # Disable LLMNR
  311. Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows NT\DNSClient" -Name "EnableMulticast" -Value 0 -Type DWord
  312. Write-Host "Disable LLMNR"
  313.  
  314. # Disable Delivery Optimization
  315. Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings" -Name "DownloadMode" -Value 0 -Type DWord
  316. Set-Service -Name "DoSvc" -StartupType Manual
  317. Write-Host "Disable Delivery Optimization"
  318.  
  319. # Enable Weak Host Model
  320. Get-NetIPInterface | Set-NetIPInterface -WeakHostReceive Enabled -WeakHostSend Enabled
  321. Write-Host "Enable Weak Host Model"
  322.  
  323. # Disable NDIS Power Management
  324. Set-TCPSetting "DisablePowerManagement" 1
  325. Write-Host "Disable NDIS Power Management"
  326.  
  327. # Disable Proportional Rate Reduction
  328. netsh int tcp set global prr=disabled | Out-Null
  329. Write-Host "Disable Proportional Rate Reduction"
  330.  
  331. # Disable Connected Standby
  332. Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Power" -Name "EnforceDisconnectedStandby" -Value 0 -Type DWord
  333. powercfg /setacvalueindex scheme_current sub_none connectivityinstandby 0
  334. powercfg /s scheme_current
  335. Write-Host "Disable Connected Standby"
  336.  
  337. # Disable Network Power Savings
  338. Disable-NetAdapterPowerManagement -Name * -NoRestart
  339. Write-Host "Disable Network Power Savings"
  340.  
  341. # Disable Network Throttling
  342. Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Psched" -Name "NonBestEffortLimit" -Value 0 -Type DWord
  343. Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile" -Name "NetworkThrottlingIndex" -Value 4294967295 -Type DWord
  344. Write-Host "Disable Network Throttling"
  345.  
  346. # Disable Network Adapter Power Saving
  347. $powerSettings = @(
  348.     # Disable Wake Features
  349.     @{Keyword="WakeOnMagicPacket"; Value="0"},
  350.     @{Keyword="WakeOnPattern"; Value="0"},
  351.     @{Keyword="WakeOnLink"; Value="0"},
  352.     @{Keyword="WakeOnLinkChange"; Value="0"},
  353.     @{Keyword="S5WakeOnLan"; Value="0"},
  354.     @{Keyword="WolShutdownLinkSpeed"; Value="2"},
  355.     @{Keyword="ModernStandbyWoLMagicPacket"; Value="0"},
  356.     @{Keyword="DeviceSleepOnDisconnect"; Value="0"},
  357.     # Disable Energy Efficient Ethernet
  358.     @{Keyword="EEE"; Value="0"},
  359.     @{Keyword="EeePhyEnable"; Value="0"},
  360.     @{Keyword="EnableGreenEthernet"; Value="0"},
  361.     @{Keyword="EEELinkAdvertisement"; Value="0"},
  362.     @{Keyword="AdvancedEEE"; Value="0"},
  363.     # Disable Ultra Low Power Mode
  364.     @{Keyword="ULPMode"; Value="0"},
  365.     # Disable Wi-Fi capability that saves power consumption
  366.     @{Keyword="uAPSDSupport"; Value="0"},
  367.     # Disable Power Saving Features
  368.     @{Keyword="NicAutoPowerSaver"; Value="0"},
  369.     @{Keyword="SelectiveSuspend"; Value="0"},
  370.     @{Keyword="EnablePME"; Value="0"},
  371.     @{Keyword="ReduceSpeedOnPowerDown"; Value="0"},
  372.     @{Keyword="PowerSavingMode"; Value="0"},
  373.     @{Keyword="SavePowerNowEnabled"; Value="0"},
  374.     @{Keyword="GigaLite"; Value="0"},
  375.     @{Keyword="EnableSavePowerNow"; Value="0"},
  376.     @{Keyword="bLowPowerEnable"; Value="0"},
  377.     @{Keyword="EnablePowerManagement"; Value="0"},
  378.     @{Keyword="EnableDynamicPowerGating"; Value="0"},
  379.     @{Keyword="DisableDelayedPowerUp"; Value="1"},
  380.     @{Keyword="EnableConnectedPowerGating"; Value="0"},
  381.     @{Keyword="AutoPowerSaveModeEnabled"; Value="0"},
  382.     @{Keyword="PowerSaveMode"; Value="0"},
  383.     @{Keyword="AutoDisableGigabit"; Value="0"},
  384.     @{Keyword="PowerDownPll"; Value="0"},
  385.     @{Keyword="S5NicKeepOverrideMacAddrV2"; Value="0"},
  386.     @{Keyword="MIMOPowerSaveMode"; Value="3"},
  387.     @{Keyword="AlternateSemaphoreDelay"; Value="0"},
  388.     @{Keyword="SipsEnabled"; Value="0"},
  389.     # Enable Throughput Booster
  390.     @{Keyword="ThroughputBoosterEnabled"; Value="1"},
  391.     # Access Point Compatibility Mode: 'High Performance'
  392.     @{Keyword="ApCompatMode"; Value="0"},
  393.     # Disable network adapter power management
  394.     @{Keyword="PnPCapabilities"; Value="24"}
  395. )
  396. foreach ($setting in $powerSettings) {
  397.     Set-NICProperty $setting.Keyword $setting.Value
  398. }
  399. Write-Host "Disable Network Adapter Power Saving"
  400.  
  401. # Increase Concurrent Connections Limit
  402. $conSettings = @(
  403.     @{Path="HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"; Name="MaxConnectionsPerServer"; Value=10},
  404.     @{Path="HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"; Name="MaxConnectionsPer1_0Server"; Value=10}
  405. )
  406. foreach ($setting in $conSettings) {
  407.     Set-ItemProperty -Path $setting.Path -Name $setting.Name -Value $setting.Value -Type DWord
  408. }
  409. Write-Host "Increase Concurrent Connections Limit"
  410.  
  411. # Remove TCP Connection Limit
  412. Set-TCPSetting "EnableConnectionRateLimiting" 0
  413. Write-Host "Remove TCP Connection Limit"
  414.  
  415. # Set Dynamic Port Range to Maximum
  416. Set-NetTCPSetting -DynamicPortRangeStartPort 1024 -DynamicPortRangeNumberOfPort 64512
  417. Set-TCPSetting "MaxUserPort" 65534
  418. Write-Host "Set Dynamic Port Range to Maximum"
  419.  
  420. # Unlimited Outstanding Send Packets
  421. Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Psched" -Name "MaxOutstandingSends" -ErrorAction SilentlyContinue
  422. Write-Host "Unlimited Outstanding Send Packets"
  423.  
  424. # Optimize TCP Acks, Sacks, and Syns
  425. $networkInterfaces = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards" |
  426.                     ForEach-Object { Get-ItemProperty $_.PSPath | Select-Object ServiceName }
  427.  
  428. foreach ($interface in $networkInterfaces) {
  429.     $path = "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\$($interface.ServiceName)"
  430.    
  431.     if (Test-Path $path) {
  432.         Set-ItemProperty -Path $path -Name "TCPNoDelay" -Value 1 -Type DWord
  433.         Set-ItemProperty -Path $path -Name "TCPAckFrequency" -Value 1 -Type DWord
  434.         Set-ItemProperty -Path $path -Name "TCPDelAckTicks" -Value 0 -Type DWord
  435.         Set-ItemProperty -Path $path -Name "TcpInitialRTT" -Value 2000 -Type DWord
  436.     }
  437. }
  438.  
  439. # Disable Nagle's Algorithm
  440. Set-TCPSetting "TCPNoDelay" 1
  441. Set-ItemProperty -Path "HKLM:\Software\Microsoft\MSMQ\Parameters" -Name "TCPNoDelay" -Value 1 -Type DWord
  442. Write-Host "Disable Nagle's Algorithm"
  443.  
  444. # Disable TCP Ack Delays
  445. Set-TCPSetting "TCPAckFrequency" 1
  446. Set-TCPSetting "TCPDelAckTicks" 0
  447. Write-Host "Disable TCP Ack Delays"
  448.  
  449. # Lower Initial Round-Trip Time (RTT)
  450. Set-TCPSetting "TCPInitialRTT" 300
  451. Write-Host "Lower Initial Round-Trip Time (RTT)"
  452.  
  453. # Lower Initial Retransmission Timeout (RTO)
  454. Set-NetTCPSetting -InitialRtoMs 2000
  455. Write-Host "Lower Initial Retransmission Timeout (RTO)"
  456.  
  457. # Lower Minimum Retransmission Timeout (RTO)
  458. # Hard Coded
  459. # Set-NetTCPSetting -MinRtoMs 20 | Out-Null
  460. # Write-Host "Lower Minimum Retransmission Timeout (RTO)"
  461.  
  462. # Decrease Max SYN Retransmissions
  463. Set-NetTCPSetting -MaxSynRetransmissions 2
  464. Write-Host "Decrease Max SYN Retransmissions"
  465.  
  466. # Decrease Max SYN/SYN-Ack Retransmissions
  467. Set-TCPSetting "TcpMaxConnectRetransmissions" 2
  468. Write-Host "Decrease Max SYN/SYN-Ack Retransmissions"
  469.  
  470. # Decrease Max Data Packet Retransmissions
  471. Set-TCPSetting "TcpMaxDataRetransmissions" 2
  472. Write-Host "Decrease Max Data Packet Retransmissions"
  473.  
  474. # Enable TCP Selective Acks (SACK) Support
  475. Set-TCPSetting "SackOpts" 1
  476. Write-Host "Enable TCP Selective Acks (SACK) Support"
  477.  
  478. # Disable RTT Resiliency for Non-SACK Clients
  479. Set-NetTCPSetting -NonSackRttResiliency Disabled
  480. Write-Host "Disable RTT Resiliency for Non-SACK Clients"
  481.  
  482. # Set TIME_WAIT Length to Minimum
  483. Set-TCPSetting "TcpTimedWaitDelay" 30
  484. Write-Host "Set TIME_WAIT Length to Minimum"
  485.  
  486. # Enable Network Direct Memory Access (NetDMA)
  487. netsh int tcp set global netdma=enabled | Out-Null
  488. Set-TCPSetting "EnableTCPA" 1
  489. Write-Host "Enable NetDMA"
  490.  
  491. # Enable Direct Cache Access (DCA)
  492. netsh int tcp set global dca=enabled | Out-Null
  493. Write-Host "Enable Direct Cache Access (DCA)"
  494.  
  495. # Enable TCP Fast Open
  496. netsh int tcp set global fastopen=enabled | Out-Null
  497. Write-Host "Enable TCP Fast Open"
  498.  
  499. # Disable Flow Control
  500. Set-NICProperty "FlowControl" "0"
  501. Write-Host "Disable Flow Control"
  502.  
  503. # Disable Interrupt Moderation
  504. Set-NICProperty "InterruptModeration" "0"
  505. Write-Host "Disable Interrupt Moderation"
  506.  
  507. # Set Max Receive/Transmit Buffers
  508. $networkCards = Get-ChildItem "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\NetworkCards" |
  509.                 ForEach-Object { Get-ItemProperty $_.PSPath | Select-Object Description }
  510.  
  511. foreach ($card in $networkCards) {
  512.     $deviceClasses = Get-ChildItem "HKLM:\System\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}" -Recurse |
  513.                     Get-ItemProperty |
  514.                     Where-Object { $_.DriverDesc -eq $card.Description }
  515.  
  516.     foreach ($device in $deviceClasses) {
  517.         $devicePath = $device.PSPath
  518.        
  519.         # ReceiveBuffers
  520.         $receiveBuffersPath = Join-Path $devicePath "Ndi\params\*ReceiveBuffers"
  521.         if (Test-Path $receiveBuffersPath) {
  522.             $maxValue = Get-ItemProperty $receiveBuffersPath -Name "Max" -ErrorAction SilentlyContinue
  523.             if ($maxValue) {
  524.                 Set-NICProperty "ReceiveBuffers" $maxValue.Max
  525.             }
  526.         }
  527.        
  528.         # TransmitBuffers
  529.         $transmitBuffersPath = Join-Path $devicePath "Ndi\params\*TransmitBuffers"
  530.         if (Test-Path $transmitBuffersPath) {
  531.             $maxValue = Get-ItemProperty $transmitBuffersPath -Name "Max" -ErrorAction SilentlyContinue
  532.             if ($maxValue) {
  533.                 Set-NICProperty "TransmitBuffers" $maxValue.Max
  534.             }
  535.         }
  536.     }
  537. }
  538. Write-Host "Set Max Receive/Transmit Buffers"
  539.  
  540. # Set Network Level Priorities
  541. $prioritySettings = @(
  542.     @{Path="HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\ServiceProvider"; Name="LocalPriority"; Value=4},
  543.     @{Path="HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\ServiceProvider"; Name="HostsPriority"; Value=5},
  544.     @{Path="HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\ServiceProvider"; Name="DnsPriority"; Value=6},
  545.     @{Path="HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\ServiceProvider"; Name="NetBtPriority"; Value=7},
  546.     @{Path="HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\ServiceProvider"; Name="Class"; Value=8}
  547. )
  548. foreach ($setting in $prioritySettings) {
  549.     Set-ItemProperty -Path $setting.Path -Name $setting.Name -Value $setting.Value -Type DWord
  550. }
  551. Write-Host "Set Network Level Priorities"
  552.  
  553. # Enable QoS
  554. Enable-NetAdapterBinding -Name * -ComponentID Ms_Pacer
  555. Set-Service -Name "Psched" -StartupType Automatic
  556. Start-Service -Name "Psched"
  557.  
  558. # Enable QoS Policies on Home Computers
  559. Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\Tcpip\QoS" -Name "Do not use NLA" -Value "1" -Type String
  560. Write-Host "Enable QoS Policies on Home Computers"
  561.  
  562. # Optimize DSCP for gaming apps
  563. $apps = @("csgo", "VALORANT-Win64-Shipping", "javaw", "FortniteClient-Win64-Shipping",
  564.           "ModernWarfare", "r5apex", "Marvel-Win64-Shipping", "ExitLag")
  565.  
  566. foreach ($app in $apps) {
  567.     Remove-NetQosPolicy -Name $app -PolicyStore PersistentStore -ErrorAction SilentlyContinue -Confirm:$false
  568.     Remove-NetQosPolicy -Name $app -PolicyStore ActiveStore -ErrorAction SilentlyContinue -Confirm:$false
  569.     New-NetQosPolicy -Name $app -AppPathNameMatchCondition "$app.exe" -DscpAction 46
  570.     New-NetQosPolicy -Name $app -AppPathNameMatchCondition "$app.exe" -DscpAction 46 -PolicyStore ActiveStore
  571. }
  572. Write-Host "Optimize DSCP For Certain Applications"
  573.  
  574. # Lower QoS TimerResolution
  575. Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\Psched" -Name "TimerResolution" -Value 1 -Type DWord
  576. Write-Host "Lower QoS TimerResolution"
  577.  
  578. # Configure Network Adapter Device Parameters
  579. $netDevices = Get-PnpDevice -Class Net | Where-Object { $_.InstanceId -like "PCI\VEN*" }
  580. foreach ($device in $netDevices) {
  581.     $devicePath = "HKLM:\System\CurrentControlSet\Enum\$($device.InstanceId)\Device Parameters\Interrupt Management\Affinity Policy"
  582.    
  583.     # Remove Network Adapter Interrupt Priority
  584.     Remove-ItemProperty -Path $devicePath -Name "DevicePriority" -ErrorAction SilentlyContinue
  585.    
  586.     # Set Network Adapter Policy to IrqPolicySpreadMessagesAcrossAllProcessors
  587.     Set-ItemProperty -Path $devicePath -Name "DevicePolicy" -Value 5 -Type DWord
  588.    
  589.     # Enable Network Adapter MSI Mode
  590.     $msiPath = "HKLM:\System\CurrentControlSet\Enum\$($device.InstanceId)\Device Parameters\Interrupt Management\MessageSignaledInterruptProperties"
  591.     Set-ItemProperty -Path $msiPath -Name "MSISupported" -Value 1 -Type DWord
  592. }
  593. Write-Host "Configure Network Adapter Device Parameters"
  594.  
  595. # Flush DNS Cache
  596. Clear-DnsClientCache
  597. Write-Host "Flush DNS Cache"
  598.  
  599. # Prompt to Restart Network
  600. $restart = Read-Host "Operations complete, would you like to restart your network adapter? (y/n)"
  601. if ($restart -eq 'y') {
  602.     # Release/Renew IP address
  603.     Get-NetAdapter | Where-Object {$_.Status -eq 'Up'} | ForEach-Object {
  604.         $interface = $_.InterfaceAlias
  605.         ipconfig /release $interface | Out-Null
  606.         ipconfig /renew $interface | Out-Null
  607.     }
  608.     Write-Host "Renew IP address"
  609.  
  610.     # Restart Network Adapter
  611.     Get-NetAdapter | Where-Object {$_.Status -eq 'Up'} | Restart-NetAdapter
  612.     Write-Host "Restart Network Adapter"
  613. }
  614.  
  615. Write-Host "Network optimization complete! Press any key to exit."
  616. $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement