powershell:落書き3
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
powershell:落書き3 [2024/06/08 10:48] – 128.22.160.91 | powershell:落書き3 [2024/07/05 03:03] (現在) – 133.106.51.50 | ||
---|---|---|---|
行 1: | 行 1: | ||
- | 適当 | + | < |
- | オンライン64Bit https://dl.google.com/tag/s/app=x64-stable-statsdef_1/ | + | |
+ | # 定義: DFビットを立ててpingを実行する関数 | ||
+ | function Test-MTU { | ||
+ | param ( | ||
+ | [string]$Target, | ||
+ | [int]$StartMTU = 800, | ||
+ | [int]$EndMTU = 1000 | ||
+ | ) | ||
+ | |||
+ | $results = @() | ||
+ | for ($mtu = $StartMTU; $mtu -le $EndMTU; $mtu++) { | ||
+ | $pingResult = Test-Connection -ComputerName $Target -Count 1 -BufferSize $mtu -DontFragment -ErrorAction SilentlyContinue | ||
+ | if ($pingResult.StatusCode -eq 0) { | ||
+ | $results += "MTU: $mtu - Success" | ||
+ | } else { | ||
+ | $results += "MTU: $mtu - Failure" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return $results | ||
+ | } | ||
+ | |||
+ | # example.comに対してMTUを800から1000の範囲でテスト | ||
+ | $target = " | ||
+ | $mtuResults = Test-MTU -Target $target | ||
+ | |||
+ | # 全インターフェイスのMTUおよびMRU設定を取得 | ||
+ | $interfaces = Get-NetAdapter | Select-Object -Property Name, MacAddress, LinkSpeed, InterfaceDescription | ||
+ | $mtuSettings = $interfaces | ForEach-Object { | ||
+ | $interfaceName = $_.Name | ||
+ | $mtu = Get-NetIPInterface -InterfaceAlias $interfaceName | Select-Object -ExpandProperty NlMtu | ||
+ | [PSCustomObject]@{ | ||
+ | Interface = $interfaceName | ||
+ | MTU = $mtu | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # 結果をファイルに書き出し | ||
+ | $logFile = " | ||
+ | $mtuResults | Out-File -FilePath $logFile | ||
+ | Add-Content -Path $logFile -Value " | ||
+ | $mtuSettings | Format-Table -AutoSize | Out-String | Add-Content -Path $logFile | ||
+ | |||
+ | Write-Host " | ||
+ | |||
+ | </code> | ||
+ | |||
+ | < | ||
+ | # PowerShellスクリプト | ||
+ | |||
+ | function Test-MTU { | ||
+ | param ( | ||
+ | [string]$hostname, | ||
+ | [int]$minMTU, | ||
+ | [int]$maxMTU | ||
+ | ) | ||
+ | |||
+ | $logFile = " | ||
+ | Remove-Item $logFile -ErrorAction SilentlyContinue | ||
+ | |||
+ | function Ping-Host { | ||
+ | param ( | ||
+ | [string]$host, | ||
+ | [int]$size | ||
+ | ) | ||
+ | |||
+ | $pingResult = Test-Connection -ComputerName $host -Count 4 -BufferSize $size -DontFragment -Quiet | ||
+ | return $pingResult | ||
+ | } | ||
+ | |||
+ | function BinarySearch-MTU { | ||
+ | param ( | ||
+ | [string]$host, | ||
+ | [int]$low, | ||
+ | [int]$high | ||
+ | ) | ||
+ | |||
+ | while ($low -le $high) { | ||
+ | $mid = [math]:: | ||
+ | |||
+ | if (Ping-Host -host $host -size $mid) { | ||
+ | $low = $mid + 1 | ||
+ | } else { | ||
+ | $high = $mid - 1 | ||
+ | } | ||
+ | } | ||
+ | return $high | ||
+ | } | ||
+ | |||
+ | # 最適なMTUサイズを探す | ||
+ | $optimalMTU = BinarySearch-MTU -host $hostname -low $minMTU -high $maxMTU | ||
+ | " | ||
+ | |||
+ | # 現在のすべてのインターフェイスのMTUおよびMRU設定を取得 | ||
+ | $interfaces = Get-NetIPInterface | ||
+ | foreach ($interface in $interfaces) { | ||
+ | $interfaceInfo = " | ||
+ | $interfaceInfo | Out-File -FilePath $logFile -Append | ||
+ | } | ||
+ | } | ||
+ | |||
+ | # 設定 | ||
+ | $hostname = " | ||
+ | $minMTU | ||
+ | $maxMTU = 1000 | ||
+ | |||
+ | # 実行 | ||
+ | Test-MTU -hostname $hostname -minMTU $minMTU -maxMTU $maxMTU | ||
+ | |||
+ | </code> | ||
- | https:// |
powershell/落書き3.1717843692.txt.gz · 最終更新: 2024/06/08 10:48 by 128.22.160.91