commit
d61c05b3d2
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 NXU
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@ -0,0 +1,43 @@
|
||||
# Switch Ethernet (PowerShell)
|
||||
|
||||
A simple script to change the priority of two Network Interfaces (NICs).
|
||||
|
||||
Useful for switching between two networks or change the priority of Ethernet and Wi-Fi.
|
||||
|
||||
|
||||
## :sparkles: Requirements
|
||||
- Text Editor
|
||||
- PowerShell
|
||||
- Only support **Windows**
|
||||
- Admin Permission
|
||||
- Basic technical knowledge
|
||||
|
||||
|
||||
## :notebook: How To Use?
|
||||
1. Open the ps1 file with text editor
|
||||
2. Open setting / control panel to view the name of both NIC
|
||||
3. Change the `$net1_name` & `$net2_name` to your NIC's name, change the `$check_ip_url` if you want
|
||||
4. Create a shortcut to the script `powershell -f <PATH_OF_THE_SCRIPT>` (For example, *`powershell -f "C:\Users\jasonfoknxu\Documents\switch-ethernet.ps1"`*)
|
||||
5. Right-click the shortcut :arrow_right: Properties :arrow_right: Shortcut (tab) :arrow_right: Advanced :arrow_right: Select **`Run as Administrator`**
|
||||
6. Execute the script by clicking the shortcut
|
||||
7. Input `1` to select first network, `2` for the second network, `0` for returning back to default (auto)
|
||||
8. Done
|
||||
|
||||
|
||||
## :star: Example
|
||||

|
||||
|
||||
There are two networks, the name are `LAN` and `Wi-Fi`
|
||||
|
||||
You can select your favorite IP checking server or empty (`$check_ip_url = ""`) to disable IP checking
|
||||
|
||||
The config would be like the following:
|
||||
```powershell
|
||||
$net1_name = "LAN"
|
||||
$net2_name = "Wi-Fi"
|
||||
$check_ip_url = "https://api.ipify.org"
|
||||
```
|
||||
|
||||
|
||||
## :gear: How it works?
|
||||
The script will change the Interface Metric of target NIC to lower, another NIC to higher Metric
|
||||
|
After Width: | Height: | Size: 20 KiB |
@ -0,0 +1,36 @@
|
||||
# switch-ethernet (PowerShell)
|
||||
# - Developer: NXU (GitHub: @jasonfoknxu)
|
||||
# - https://github.com/jasonfoknxu/
|
||||
# - Switch network with changing the Metric (Lower = Higher Priority)
|
||||
|
||||
### ---------- ###
|
||||
|
||||
$net1_name = "Ethernet" # Input the name of first network interface
|
||||
$net2_name = "Ethernet 2" # Input the name of second network interface
|
||||
$check_ip_url = "http://ipinfo.io/ip" # URL to check the current IP address (empty to disable checking)
|
||||
|
||||
### ---------- ###
|
||||
|
||||
$option = Read-Host "Networks:`n0 - Auto`n1 - $net1_name`n2 - $net2_name`nSwitch to"
|
||||
|
||||
if ($option -eq 1) {
|
||||
Write-Host "Switching to $net1_name"
|
||||
Get-NetAdapter -Name $net1_name | Set-NetIPInterface -InterfaceMetric "5"
|
||||
Get-NetAdapter -Name $net2_name | Set-NetIPInterface -InterfaceMetric "10"
|
||||
}
|
||||
elseif ($option -eq 2) {
|
||||
Write-Host "Switching to $net2_name"
|
||||
Get-NetAdapter -Name $net1_name | Set-NetIPInterface -InterfaceMetric "10"
|
||||
Get-NetAdapter -Name $net2_name | Set-NetIPInterface -InterfaceMetric "5"
|
||||
}
|
||||
else {
|
||||
Write-Host "Switching to Auto LAN"
|
||||
Get-NetAdapter -Name $net1_name | Set-NetIPInterface -AutomaticMetric enabled
|
||||
Get-NetAdapter -Name $net2_name | Set-NetIPInterface -AutomaticMetric enabled
|
||||
}
|
||||
if ($check_ip_url -ne "") {
|
||||
$currentIP = (Invoke-WebRequest -UseBasicParsing -Uri $check_ip_url).Content.Trim()
|
||||
Write-Host "Current IP: $currentIP"
|
||||
}
|
||||
|
||||
CMD /c PAUSE
|
||||
Loading…
Reference in new issue