> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/powershell-programming-and-relative-experience/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/powershell-programming-and-relative-experience/chapter3_test_case_for_windows_7_10/38ethernet-throughput-interactions.md).

# 3.8.Ethernet-throughput interactions

* Sequence Diagram

  ![](https://117590093-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4M0G8MrI9JbdRm_9nH%2F-M4M0I_MusDflHE0g_CK%2F-M4M0_N_aHLr4b6xcsuW%2F%E6%9C%AA%E5%91%BD2%E5%90%8D.jpg?generation=1586302968469611\&alt=media)
* Programming
  * 1.iperf UDP server

    ```
            $p = Start-Process -FilePath "$serverDrive\$serverShareFolder\$iperfdir\iperf.exe" -ArgumentList "-s -u -w 256k"
            #echo  $p
            $id=(get-process iperf).Id
            Wait-Process -id $id -timeout ($timeout_iperf +20)

            $iperf = Get-Process iperf -ErrorAction SilentlyContinue
            if ($iperf) {
              taskkill /T /F /PID $id
            }
    ```
  * 2.iperf UDP client

    ```
            $_bandwidth=$bandwidth+"M"  
            $pinfo = New-Object System.Diagnostics.ProcessStartInfo
            $pinfo.FileName = "$serverDrive\$serverShareFolder\$iperfdir\iperf.exe" 
            $pinfo.Arguments="-u -c $clientIP -t $timeout_iperf -i 1 -f 'm' -b $_bandwidth -w 256k"
            $pinfo.UseShellExecute = $false
            $pinfo.CreateNoWindow = $true
            $pinfo.RedirectStandardOutput = $true
            $p = New-Object System.Diagnostics.Process
            $p.StartInfo = $pinfo
            $p.Start() | Out-Null
            $p.WaitForExit()
            $stdout = $p.StandardOutput.ReadToEnd()
    ```
  * 3.iperf TCP server

    ```
            $p = Start-Process -FilePath "$serverDrive\$serverShareFolder\$iperfdir\iperf.exe" -ArgumentList "-s -w 256k"
            $id=(get-process iperf).Id
            Wait-Process -id $id -timeout ($timeout_iperf +20)
            $iperf = Get-Process iperf -ErrorAction SilentlyContinue
            if ($iperf) {
              taskkill /T /F /PID $id
            }
    ```
  * 4.iperf TCP client

```
            $pinfo = New-Object System.Diagnostics.ProcessStartInfo
            $pinfo.FileName = "$serverDrive\$serverShareFolder\$iperfdir\iperf.exe"
            $pinfo.Arguments="-c $clientIP -t $timeout_iperf -i 1 -f 'm' -w 256k"
            $pinfo.UseShellExecute = $false
            $pinfo.CreateNoWindow = $true
            $pinfo.RedirectStandardOutput = $true
            $p = New-Object System.Diagnostics.Process
            $p.StartInfo = $pinfo
            $p.Start() | Out-Null
            $p.WaitForExit()
            $stdout = $p.StandardOutput.ReadToEnd()
```

* 5.Change NIC speed & duplex mode      &#x20;

```
            Param (   
                         [parameter(mandatory=$False,HelpMessage='threshold for performane test')]      
                         [string]$computer
                         [parameter(mandatory=$False,HelpMessage='disk type for performane test')]     
                         [string]$speed = "1"     
             )  
          #"0" {$duplex = "Auto Detect"}            
          #"1" {$duplex = "10Mbps \ Half Duplex"}            
          #"2" {$duplex = "10Mbps \ Full Duplex"}            
          #"3" {$duplex = "100Mbps \ Half Duplex"}            
          #"4" {$duplex = "100Mbps \ Full Duplex"}     
          #"6" {$duplex = "1Gbps \ Full Duplex"}     

          #$computer = "192.168.31.22"
          #$speed = "1"
          $HKLM = 2147483650            
          $reg = [wmiclass]"\\$computer\root\default:StdRegprov"            
          $keyroot = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"            

          Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $computer -Filter "IPEnabled='$true'" |            
          foreach {            

              $data = $_.Caption -split "]"            
              $suffix = $data[0].Substring(($data[0].length-4),4)            
              $key = $keyroot + "\$suffix" 

              $value = "*SpeedDuplex"            
              $dup = $reg.SetStringValue($HKLM, $key, $value, $speed)  ## REG_SZ       

              $nic = $_.GetRelated("Win32_NetworkAdapter") | select Speed, NetConnectionId            

              netsh interface set interface $nic.NetConnectionID DISABLED  
              netsh interface set interface $nic.NetConnectionID ENABLED 
          }
```
