Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ef0d77ca6 | |||
| 7350232362 | |||
| 67447bc7f1 | |||
| e80e673a10 | |||
| 408126f177 | |||
| c4d98dd5e3 | |||
| 789c7b3750 | |||
| a854d8e3f7 | |||
| 18eac693e9 | |||
| ebe64363c6 |
@@ -0,0 +1,55 @@
|
|||||||
|
name: Bug report
|
||||||
|
description: Something doesn't work as expected
|
||||||
|
labels: ["bug"]
|
||||||
|
body:
|
||||||
|
- type: input
|
||||||
|
id: version
|
||||||
|
attributes:
|
||||||
|
label: Version
|
||||||
|
description: Visible in the startup banner.
|
||||||
|
placeholder: v1.0.0
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: steps
|
||||||
|
attributes:
|
||||||
|
label: Steps to reproduce
|
||||||
|
placeholder: |
|
||||||
|
1. ...
|
||||||
|
2. ...
|
||||||
|
3. ...
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: expected
|
||||||
|
attributes:
|
||||||
|
label: What you expected to happen
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: actual
|
||||||
|
attributes:
|
||||||
|
label: What actually happened
|
||||||
|
description: Paste any error output verbatim. Screenshots are welcome.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: os
|
||||||
|
attributes:
|
||||||
|
label: Windows version
|
||||||
|
placeholder: e.g. Windows 11 24H2
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: adapter
|
||||||
|
attributes:
|
||||||
|
label: Adapter (if relevant)
|
||||||
|
placeholder: e.g. Realtek USB GbE Family Controller
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: extra
|
||||||
|
attributes:
|
||||||
|
label: Anything else?
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Security vulnerability
|
||||||
|
url: https://github.com/Engelgardt23/netswitch/security/advisories/new
|
||||||
|
about: Please report security issues privately via GitHub Security Advisories — not as a public issue.
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
name: Feature request
|
||||||
|
description: Suggest a new feature or an improvement
|
||||||
|
labels: ["enhancement"]
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: motivation
|
||||||
|
attributes:
|
||||||
|
label: What's the use case?
|
||||||
|
description: What are you trying to do, and why is the current behavior not enough?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: proposal
|
||||||
|
attributes:
|
||||||
|
label: Proposed solution
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: alternatives
|
||||||
|
attributes:
|
||||||
|
label: Alternatives considered
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*.*.*'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Resolve version from tag
|
||||||
|
id: ver
|
||||||
|
shell: bash
|
||||||
|
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Install ps2exe
|
||||||
|
shell: pwsh
|
||||||
|
run: Install-Module -Name ps2exe -Scope CurrentUser -Force -AllowClobber
|
||||||
|
|
||||||
|
- name: Build executable
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
Import-Module ps2exe
|
||||||
|
$ver = '${{ steps.ver.outputs.version }}'
|
||||||
|
Invoke-ps2exe -inputFile src/netswitch.ps1 -outputFile netswitch.exe `
|
||||||
|
-title "netswitch" -description "NIC IP/DHCP toggle - made by engelgardt" `
|
||||||
|
-company "engelgardt" -version "$ver.0" `
|
||||||
|
-iconFile assets/icon.ico `
|
||||||
|
-requireAdmin
|
||||||
|
|
||||||
|
- name: Package portable folder
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$ver = '${{ steps.ver.outputs.version }}'
|
||||||
|
$folder = "netswitch-v$ver"
|
||||||
|
New-Item -ItemType Directory -Path $folder | Out-Null
|
||||||
|
Copy-Item netswitch.exe $folder/
|
||||||
|
@"
|
||||||
|
netswitch v$ver - portable edition
|
||||||
|
made by engelgardt
|
||||||
|
|
||||||
|
Quickly set a Windows network adapter to a static IP or back to DHCP.
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
Double-click netswitch.exe.
|
||||||
|
Accept the UAC prompt.
|
||||||
|
Pick the NIC, then choose mode (Static / DHCP).
|
||||||
|
Press Enter to exit.
|
||||||
|
|
||||||
|
NOTES
|
||||||
|
- Nothing is installed. Delete the folder to remove.
|
||||||
|
- Requires Windows 10/11.
|
||||||
|
- PowerShell is bundled into the exe via ps2exe; nothing extra needed.
|
||||||
|
"@ | Out-File -FilePath "$folder/README.txt" -Encoding UTF8
|
||||||
|
Compress-Archive -Path $folder -DestinationPath "netswitch-portable-v$ver.zip"
|
||||||
|
|
||||||
|
- name: Generate SHA-256 checksum
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$ver = '${{ steps.ver.outputs.version }}'
|
||||||
|
$zip = "netswitch-portable-v$ver.zip"
|
||||||
|
$hash = (Get-FileHash -Algorithm SHA256 $zip).Hash.ToLower()
|
||||||
|
"$hash $zip" | Out-File -FilePath "$zip.sha256" -Encoding ASCII -NoNewline
|
||||||
|
Get-Content "$zip.sha256"
|
||||||
|
|
||||||
|
- name: Create release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
netswitch-portable-v${{ steps.ver.outputs.version }}.zip
|
||||||
|
netswitch-portable-v${{ steps.ver.outputs.version }}.zip.sha256
|
||||||
|
generate_release_notes: true
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to **netswitch** are documented in this file.
|
||||||
|
|
||||||
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [1.1.0] - 2026-05-18
|
||||||
|
### Added
|
||||||
|
- Russian UI translation. On first launch the application asks which language to use (`1) English`, `2) Русский`) and writes the answer to a fresh `config.ini` next to `netswitch.exe`. To change the language later, edit `language = en` / `language = ru` in that file — the comment at the top of the file explains how, in both languages.
|
||||||
|
- Bilingual `README.ru.md` linked from the main `README.md`.
|
||||||
|
|
||||||
|
## [1.0.3] - 2026-05-17
|
||||||
|
### Changed
|
||||||
|
- Update check no longer interrupts startup with an interactive prompt. If a newer release is available, a quiet right-aligned `update available (vX.Y.Z)` hint is printed in dim grey directly under the banner — no key press required.
|
||||||
|
|
||||||
|
## [1.0.2] - 2026-05-17
|
||||||
|
### Fixed
|
||||||
|
- Suppress `netsh` output to avoid mojibake on non-UTF-8 consoles (Russian Windows printed `╤Г╨╢╨╡ ╨▓╨║╨╗╤О╤З╨╡╨╜╨╛...` because netsh emits in the OEM code page). Our own English status lines remain; the post-change `Get-NetIPAddress` block already prints Unicode.
|
||||||
|
|
||||||
|
## [1.0.1] - 2026-05-17
|
||||||
|
### Changed
|
||||||
|
- Dropped the `made by engelgardt` line from the startup banner — keep author credit in the README only.
|
||||||
|
### Added
|
||||||
|
- Embedded application icon in the exe (via ps2exe `-iconFile assets/icon.ico`).
|
||||||
|
|
||||||
|
## [1.0.0] - 2026-05-16
|
||||||
|
### Added
|
||||||
|
- First public release on GitHub.
|
||||||
|
- Portable `.exe` (~30 KB) built from PowerShell via ps2exe.
|
||||||
|
- Self-elevation through UAC.
|
||||||
|
- Physical wired NIC filter — Wi-Fi, VPN, virtual, Hyper-V, VMware, VirtualBox, TAP/TUN, WireGuard, OpenVPN, Tailscale, ZeroTier, Bluetooth, Loopback and WAN Miniport adapters are hidden from the picker.
|
||||||
|
- Two modes: **Static** (default `10.10.10.1/24`, optional gateway) and **DHCP**.
|
||||||
|
- Current IPv4 configuration is printed after the change.
|
||||||
|
- Auto-update check on startup: polls GitHub `/releases/latest` with a 3-second timeout and offers to open the download page if a newer version exists. Silent on offline / API errors.
|
||||||
|
- MIT licensed.
|
||||||
|
|
||||||
|
[Unreleased]: https://github.com/Engelgardt23/netswitch/compare/v1.1.0...HEAD
|
||||||
|
[1.1.0]: https://github.com/Engelgardt23/netswitch/compare/v1.0.3...v1.1.0
|
||||||
|
[1.0.3]: https://github.com/Engelgardt23/netswitch/compare/v1.0.2...v1.0.3
|
||||||
|
[1.0.2]: https://github.com/Engelgardt23/netswitch/compare/v1.0.1...v1.0.2
|
||||||
|
[1.0.1]: https://github.com/Engelgardt23/netswitch/compare/v1.0.0...v1.0.1
|
||||||
|
[1.0.0]: https://github.com/Engelgardt23/netswitch/releases/tag/v1.0.0
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
> Project layout, build, and release flow. **If you only want to use the tool — read [README](README.md) instead.**
|
||||||
|
|
||||||
|
## Repo layout
|
||||||
|
|
||||||
|
```
|
||||||
|
netswitch/
|
||||||
|
├── .github/
|
||||||
|
│ ├── workflows/release.yml ← CI: tag-driven build + GitHub Release
|
||||||
|
│ └── ISSUE_TEMPLATE/ ← bug / feature / security routing
|
||||||
|
├── src/
|
||||||
|
│ └── netswitch.ps1 ← the whole tool (~150 lines)
|
||||||
|
├── CHANGELOG.md ← Keep a Changelog format, newest first
|
||||||
|
├── CONTRIBUTING.md ← this file
|
||||||
|
├── LICENSE / README.md / SECURITY.md
|
||||||
|
└── .gitignore
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run from source (no exe)
|
||||||
|
|
||||||
|
```
|
||||||
|
powershell -ExecutionPolicy Bypass -File src/netswitch.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
The script self-elevates through UAC if you launched it without admin.
|
||||||
|
|
||||||
|
## Build the portable .exe locally
|
||||||
|
|
||||||
|
```
|
||||||
|
Install-Module ps2exe -Scope CurrentUser
|
||||||
|
Invoke-ps2exe -inputFile src/netswitch.ps1 -outputFile netswitch.exe `
|
||||||
|
-title "netswitch" -description "NIC IP/DHCP toggle - made by engelgardt" `
|
||||||
|
-company "engelgardt" -version "1.0.0.0" `
|
||||||
|
-requireAdmin
|
||||||
|
```
|
||||||
|
|
||||||
|
## Cut a release
|
||||||
|
|
||||||
|
1. Update `src/netswitch.ps1` — bump `$NetswitchVersion` to `X.Y.Z`.
|
||||||
|
2. Update `CHANGELOG.md` — move items from `[Unreleased]` into a new `[X.Y.Z]` section with today's date.
|
||||||
|
3. Commit: `git commit -am "vX.Y.Z: …"`.
|
||||||
|
4. Tag: `git tag vX.Y.Z`.
|
||||||
|
5. Push: `git push && git push --tags`.
|
||||||
|
|
||||||
|
GitHub Actions picks up the tag, builds the exe via ps2exe, writes the SHA-256, and creates the GitHub Release with the zip attached.
|
||||||
|
|
||||||
|
## Where features go
|
||||||
|
|
||||||
|
The whole tool is a single PowerShell file with these sections (in order):
|
||||||
|
|
||||||
|
1. `$NetswitchVersion` / `$GithubRepo` — top of file.
|
||||||
|
2. **Self-elevate** block — UAC if non-admin.
|
||||||
|
3. **Banner** — Write-Host title.
|
||||||
|
4. **`Test-NetswitchUpdate`** — GitHub /releases/latest poll.
|
||||||
|
5. **Adapter filter + picker** — `$skipDescriptionPattern`, `$skipMediaTypes`, `Get-NetAdapter | Where-Object {...}`.
|
||||||
|
6. **Mode prompt** — Static / DHCP.
|
||||||
|
7. **Static branch** — `netsh interface ipv4 set address ... static ...`.
|
||||||
|
8. **DHCP branch** — `netsh interface ipv4 set address ... source=dhcp`.
|
||||||
|
9. **Current config display** — `Get-NetIPAddress | Format-Table`.
|
||||||
|
|
||||||
|
If a section grows past ~50 lines, factor it into `src/lib/<thing>.ps1` and dot-source it from the main file.
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
[](https://github.com/Engelgardt23/netswitch/releases/latest)
|
[](https://github.com/Engelgardt23/netswitch/releases/latest)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
|
|
||||||
|
🇬🇧 English | [🇷🇺 На русском](README.ru.md)
|
||||||
|
|
||||||
A tiny portable tool to flip a Windows network adapter between a **static IP** and **DHCP** with a few keystrokes.
|
A tiny portable tool to flip a Windows network adapter between a **static IP** and **DHCP** with a few keystrokes.
|
||||||
|
|
||||||
Built for the recurring engineer chore of "give my laptop NIC 10.10.10.1 so I can talk to a server's BMC" and "now put it back on DHCP so I can have internet again."
|
Built for the recurring engineer chore of "give my laptop NIC 10.10.10.1 so I can talk to a server's BMC" and "now put it back on DHCP so I can have internet again."
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
# netswitch
|
||||||
|
|
||||||
|
[](https://github.com/Engelgardt23/netswitch/releases/latest)
|
||||||
|
[](LICENSE)
|
||||||
|
|
||||||
|
[🇬🇧 English](README.md) | 🇷🇺 На русском
|
||||||
|
|
||||||
|
Маленький портативный инструмент, который за пару нажатий переключает сетевой адаптер Windows между **статическим IP** и **DHCP**.
|
||||||
|
|
||||||
|
Решает регулярную задачу инженера: «дай моему ноуту 10.10.10.1, чтобы я мог достучаться до BMC сервера», а потом «верни обратно на DHCP, чтобы был интернет».
|
||||||
|
|
||||||
|
> **Автор: engelgardt.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Скачать
|
||||||
|
|
||||||
|
Последний релиз: [**страница релизов**](https://github.com/Engelgardt23/netswitch/releases/latest).
|
||||||
|
Архив `netswitch-portable-vX.Y.Z.zip` (~30 КБ).
|
||||||
|
|
||||||
|
## Запуск
|
||||||
|
|
||||||
|
1. Распакуй куда угодно.
|
||||||
|
2. Двойной клик по `netswitch.exe`.
|
||||||
|
3. **При первом запуске** программа спросит язык интерфейса (1 — English, 2 — Русский). Ответ запишется в `config.ini` рядом с exe — потом можно поменять руками.
|
||||||
|
4. Подтверди UAC (admin нужен для `netsh interface ipv4 set address`).
|
||||||
|
5. Выбери сетевой адаптер из списка.
|
||||||
|
6. Выбери режим:
|
||||||
|
- **Статический**: введи IP (по умолчанию `10.10.10.1`), маску (по умолчанию `255.255.255.0`), шлюз (опционально).
|
||||||
|
- **DHCP**: подтверди — адаптер вернётся в DHCP для IP и DNS.
|
||||||
|
|
||||||
|
## Что фильтруется
|
||||||
|
|
||||||
|
В выбор попадают только настоящие проводные физические адаптеры. Wi-Fi, VPN, виртуалки, Hyper-V, VMware, VirtualBox, TAP/TUN, WireGuard, OpenVPN, Tailscale, ZeroTier, Bluetooth, Loopback, WAN Miniport — всё пропускается.
|
||||||
|
|
||||||
|
## Проверка обновлений
|
||||||
|
|
||||||
|
При каждом запуске тулза стучится в GitHub `/releases/latest` (таймаут 3 секунды). Если есть свежая версия — справа в шапке появится тусклая надпись `доступно обновление (vX.Y.Z)`. Если интернета нет — молчит.
|
||||||
|
|
||||||
|
## Конфиг
|
||||||
|
|
||||||
|
При первом запуске рядом с `netswitch.exe` появится `config.ini`:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# Чтобы сменить язык интерфейса, измените 'language' ниже.
|
||||||
|
# Допустимые значения: en, ru
|
||||||
|
[General]
|
||||||
|
language = ru
|
||||||
|
```
|
||||||
|
|
||||||
|
## Сборка из исходников
|
||||||
|
|
||||||
|
Скрипт один — `netswitch.ps1`. Для пересборки `.exe`:
|
||||||
|
|
||||||
|
```
|
||||||
|
Install-Module ps2exe -Scope CurrentUser
|
||||||
|
Invoke-ps2exe -inputFile netswitch.ps1 -outputFile netswitch.exe -requireAdmin -title "netswitch" -version 1.1.0.0
|
||||||
|
```
|
||||||
|
|
||||||
|
## Лицензия
|
||||||
|
|
||||||
|
MIT — см. [LICENSE](LICENSE).
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
# Security policy
|
||||||
|
|
||||||
|
Thanks for taking the time to look at this. Even small tools can introduce real
|
||||||
|
risk — this one reconfigures network adapters from an elevated process — so
|
||||||
|
vulnerability reports are very welcome.
|
||||||
|
|
||||||
|
## Supported versions
|
||||||
|
|
||||||
|
Only the latest tagged release on GitHub is supported. Older versions will not
|
||||||
|
get fixes; please upgrade first.
|
||||||
|
|
||||||
|
## How to report a vulnerability
|
||||||
|
|
||||||
|
**Please do not open a public issue** for security-sensitive findings.
|
||||||
|
|
||||||
|
Use GitHub's private security advisories: go to the
|
||||||
|
[Security tab](../../security/advisories/new) of this repo and click
|
||||||
|
"Report a vulnerability". GitHub will route it privately.
|
||||||
|
|
||||||
|
Please include:
|
||||||
|
- The version you tested (the startup banner is enough).
|
||||||
|
- Steps to reproduce.
|
||||||
|
- An assessment of impact.
|
||||||
|
|
||||||
|
Reports are reviewed and addressed on a best-effort basis. A fix and a public
|
||||||
|
advisory will be published once the issue is resolved. Reporters are credited
|
||||||
|
unless they prefer to stay anonymous.
|
||||||
|
|
||||||
|
## Out of scope
|
||||||
|
|
||||||
|
- Behavior when run **without** administrator privileges (the tool refuses to
|
||||||
|
start in that case anyway).
|
||||||
|
- Issues that require the attacker to already control the user's machine.
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
-143
@@ -1,143 +0,0 @@
|
|||||||
# netswitch v1.0.0 - quick NIC IP / DHCP toggle
|
|
||||||
# made by engelgardt
|
|
||||||
|
|
||||||
$NetswitchVersion = '1.0.0'
|
|
||||||
$GithubRepo = 'Engelgardt23/netswitch'
|
|
||||||
|
|
||||||
$ErrorActionPreference = 'Stop'
|
|
||||||
|
|
||||||
# --- Self-elevate if not admin (no-op when launched from the ps2exe build which already requests admin) ---
|
|
||||||
$me = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
|
|
||||||
if (-not $me.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
||||||
if ($PSCommandPath) {
|
|
||||||
Start-Process -FilePath 'powershell.exe' `
|
|
||||||
-ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-File',"`"$PSCommandPath`"") `
|
|
||||||
-Verb RunAs
|
|
||||||
} else {
|
|
||||||
Start-Process -FilePath ([System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName) -Verb RunAs
|
|
||||||
}
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
|
|
||||||
# --- Banner ---
|
|
||||||
Write-Host ""
|
|
||||||
Write-Host "==============================================" -ForegroundColor Cyan
|
|
||||||
Write-Host " netswitch v$NetswitchVersion - NIC IP/DHCP toggle" -ForegroundColor Cyan
|
|
||||||
Write-Host " made by engelgardt" -ForegroundColor DarkCyan
|
|
||||||
Write-Host "==============================================" -ForegroundColor Cyan
|
|
||||||
Write-Host ""
|
|
||||||
|
|
||||||
# --- Update check ---
|
|
||||||
function Test-NetswitchUpdate {
|
|
||||||
try {
|
|
||||||
$url = "https://api.github.com/repos/$GithubRepo/releases/latest"
|
|
||||||
$r = Invoke-RestMethod -Uri $url -TimeoutSec 3 -Headers @{ 'User-Agent' = "netswitch/$NetswitchVersion" }
|
|
||||||
$latest = ($r.tag_name -as [string]) -replace '^v',''
|
|
||||||
if (-not $latest) { return }
|
|
||||||
$toTuple = { param($s)
|
|
||||||
$parts = ($s -split '\.') | ForEach-Object {
|
|
||||||
$n = 0; [void][int]::TryParse($_, [ref]$n); $n
|
|
||||||
}
|
|
||||||
while ($parts.Count -lt 3) { $parts += 0 }
|
|
||||||
,$parts[0..2]
|
|
||||||
}
|
|
||||||
$L = & $toTuple $latest
|
|
||||||
$C = & $toTuple $NetswitchVersion
|
|
||||||
$isNewer = $false
|
|
||||||
for ($i = 0; $i -lt 3; $i++) {
|
|
||||||
if ($L[$i] -gt $C[$i]) { $isNewer = $true; break }
|
|
||||||
if ($L[$i] -lt $C[$i]) { break }
|
|
||||||
}
|
|
||||||
if ($isNewer) {
|
|
||||||
Write-Host "Update available: v$NetswitchVersion -> $($r.tag_name)" -ForegroundColor Yellow
|
|
||||||
$ans = Read-Host "Open the download page in your browser? [Y/n]"
|
|
||||||
if ($ans -notmatch '^(n|N|no|NO)$') {
|
|
||||||
Start-Process $r.html_url
|
|
||||||
}
|
|
||||||
Write-Host ""
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
# silent on offline / API errors
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Test-NetswitchUpdate
|
|
||||||
|
|
||||||
# --- Pick adapter (physical wired only) ---
|
|
||||||
$skipDescriptionPattern = 'VPN|Virtual|AnyConnect|TAP-|TUN-|Bluetooth|Loopback|WAN Miniport|Hyper-V|VMware|VirtualBox|WireGuard|OpenVPN|Tailscale|ZeroTier'
|
|
||||||
$skipMediaTypes = @('Native 802.11', 'Wireless WAN')
|
|
||||||
|
|
||||||
$adapters = @(Get-NetAdapter | Where-Object {
|
|
||||||
$_.Status -notin @('Disabled','Not Present') -and
|
|
||||||
-not $_.Virtual -and
|
|
||||||
$_.MediaType -notin $skipMediaTypes -and
|
|
||||||
$_.InterfaceDescription -notmatch $skipDescriptionPattern -and
|
|
||||||
$_.Name -notmatch $skipDescriptionPattern
|
|
||||||
} | Sort-Object ifIndex)
|
|
||||||
|
|
||||||
if ($adapters.Count -eq 0) {
|
|
||||||
Write-Host "No physical wired adapters found." -ForegroundColor Red
|
|
||||||
Read-Host "Press Enter to exit"; exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Available adapters:"
|
|
||||||
for ($i = 0; $i -lt $adapters.Count; $i++) {
|
|
||||||
$a = $adapters[$i]
|
|
||||||
$ips = (Get-NetIPAddress -InterfaceIndex $a.ifIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue |
|
|
||||||
Where-Object { $_.PrefixOrigin -ne 'WellKnown' }).IPAddress -join ', '
|
|
||||||
Write-Host (" {0}) [{1,-12}] {2} ({3}) {4}" -f ($i + 1), $a.Status, $a.Name, $a.InterfaceDescription, $ips)
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
$sel = (Read-Host "Select adapter number").Trim()
|
|
||||||
$valid = ($sel -match '^\d+$') -and ([int]$sel -ge 1) -and ([int]$sel -le $adapters.Count)
|
|
||||||
if (-not $valid) { Write-Host "Invalid selection." -ForegroundColor Red }
|
|
||||||
} while (-not $valid)
|
|
||||||
$nic = $adapters[[int]$sel - 1]
|
|
||||||
Write-Host ""
|
|
||||||
Write-Host "Selected: $($nic.Name)" -ForegroundColor Green
|
|
||||||
|
|
||||||
# --- Mode ---
|
|
||||||
Write-Host ""
|
|
||||||
Write-Host "Mode:"
|
|
||||||
Write-Host " 1) Static IP"
|
|
||||||
Write-Host " 2) DHCP"
|
|
||||||
$modeChoice = Read-Host "Choice [1]"
|
|
||||||
if ([string]::IsNullOrWhiteSpace($modeChoice)) { $modeChoice = '1' }
|
|
||||||
|
|
||||||
if ($modeChoice.Trim() -eq '2') {
|
|
||||||
# --- DHCP ---
|
|
||||||
Write-Host ""
|
|
||||||
Write-Host "Setting $($nic.Name) to DHCP..." -ForegroundColor Yellow
|
|
||||||
& netsh interface ipv4 set address name="$($nic.Name)" source=dhcp
|
|
||||||
& netsh interface ipv4 set dnsservers name="$($nic.Name)" source=dhcp
|
|
||||||
Write-Host "Done." -ForegroundColor Green
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# --- Static ---
|
|
||||||
$ip = Read-Host "IP address [10.10.10.1]"
|
|
||||||
if ([string]::IsNullOrWhiteSpace($ip)) { $ip = '10.10.10.1' }
|
|
||||||
|
|
||||||
$mask = Read-Host "Subnet mask [255.255.255.0]"
|
|
||||||
if ([string]::IsNullOrWhiteSpace($mask)) { $mask = '255.255.255.0' }
|
|
||||||
|
|
||||||
$gw = Read-Host "Gateway (Enter to skip)"
|
|
||||||
|
|
||||||
Write-Host ""
|
|
||||||
Write-Host "Setting $($nic.Name) -> $ip / $mask$( if ($gw) { " via $gw" })" -ForegroundColor Yellow
|
|
||||||
|
|
||||||
if ([string]::IsNullOrWhiteSpace($gw)) {
|
|
||||||
& netsh interface ipv4 set address name="$($nic.Name)" static $ip $mask
|
|
||||||
} else {
|
|
||||||
& netsh interface ipv4 set address name="$($nic.Name)" static $ip $mask $gw
|
|
||||||
}
|
|
||||||
Write-Host "Done." -ForegroundColor Green
|
|
||||||
}
|
|
||||||
|
|
||||||
# --- Show current state ---
|
|
||||||
Write-Host ""
|
|
||||||
Write-Host "Current IPv4 config:" -ForegroundColor Cyan
|
|
||||||
Get-NetIPAddress -InterfaceIndex $nic.ifIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue |
|
|
||||||
Where-Object { $_.PrefixOrigin -ne 'WellKnown' } |
|
|
||||||
Format-Table IPAddress, PrefixLength, PrefixOrigin -AutoSize
|
|
||||||
|
|
||||||
Read-Host "Press Enter to exit"
|
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
# netswitch - quick NIC IP / DHCP toggle
|
||||||
|
# made by engelgardt
|
||||||
|
|
||||||
|
$NetswitchVersion = '1.1.0'
|
||||||
|
$GithubRepo = 'Engelgardt23/netswitch'
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
# --- Self-elevate if not admin (no-op when launched from the ps2exe build which already requests admin) ---
|
||||||
|
$me = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
|
||||||
|
if (-not $me.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||||
|
if ($PSCommandPath) {
|
||||||
|
Start-Process -FilePath 'powershell.exe' `
|
||||||
|
-ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-File',"`"$PSCommandPath`"") `
|
||||||
|
-Verb RunAs
|
||||||
|
} else {
|
||||||
|
Start-Process -FilePath ([System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName) -Verb RunAs
|
||||||
|
}
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Locate config.ini next to the exe / script ---
|
||||||
|
function Get-AppDir {
|
||||||
|
if ($PSCommandPath) { return (Split-Path $PSCommandPath -Parent) }
|
||||||
|
try {
|
||||||
|
return Split-Path ([System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName) -Parent
|
||||||
|
} catch {
|
||||||
|
return (Get-Location).Path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$AppDir = Get-AppDir
|
||||||
|
$ConfigPath = Join-Path $AppDir 'config.ini'
|
||||||
|
|
||||||
|
# --- Bilingual UI strings ---
|
||||||
|
$STR = @{
|
||||||
|
en = @{
|
||||||
|
no_adapters = 'No physical wired adapters found.'
|
||||||
|
press_enter = 'Press Enter to exit'
|
||||||
|
available_adapters = 'Available adapters:'
|
||||||
|
select_adapter = 'Select adapter number'
|
||||||
|
invalid_selection = 'Invalid selection.'
|
||||||
|
selected = 'Selected: {0}'
|
||||||
|
mode_header = 'Mode:'
|
||||||
|
mode_static = ' 1) Static IP'
|
||||||
|
mode_dhcp = ' 2) DHCP'
|
||||||
|
mode_choice = 'Choice [1]'
|
||||||
|
setting_dhcp = 'Setting {0} to DHCP...'
|
||||||
|
done = 'Done.'
|
||||||
|
ip_prompt = 'IP address [10.10.10.1]'
|
||||||
|
mask_prompt = 'Subnet mask [255.255.255.0]'
|
||||||
|
gw_prompt = 'Gateway (Enter to skip)'
|
||||||
|
setting_static = 'Setting {0} -> {1} / {2}{3}'
|
||||||
|
via_gw = ' via {0}'
|
||||||
|
current_config = 'Current IPv4 config:'
|
||||||
|
update_available = 'update available ({0})'
|
||||||
|
lang_select = 'Select language / Выберите язык:'
|
||||||
|
lang_en = ' 1) English'
|
||||||
|
lang_ru = ' 2) Русский'
|
||||||
|
lang_invalid = 'Please enter 1 or 2 / Введите 1 или 2'
|
||||||
|
banner_subtitle = 'NIC IP/DHCP toggle'
|
||||||
|
}
|
||||||
|
ru = @{
|
||||||
|
no_adapters = 'Подходящие проводные адаптеры не найдены.'
|
||||||
|
press_enter = 'Нажмите Enter для выхода'
|
||||||
|
available_adapters = 'Доступные адаптеры:'
|
||||||
|
select_adapter = 'Введите номер адаптера'
|
||||||
|
invalid_selection = 'Неверный выбор.'
|
||||||
|
selected = 'Выбрано: {0}'
|
||||||
|
mode_header = 'Режим:'
|
||||||
|
mode_static = ' 1) Статический IP'
|
||||||
|
mode_dhcp = ' 2) DHCP'
|
||||||
|
mode_choice = 'Выбор [1]'
|
||||||
|
setting_dhcp = 'Перевожу {0} в режим DHCP...'
|
||||||
|
done = 'Готово.'
|
||||||
|
ip_prompt = 'IP-адрес [10.10.10.1]'
|
||||||
|
mask_prompt = 'Маска подсети [255.255.255.0]'
|
||||||
|
gw_prompt = 'Шлюз (Enter — пропустить)'
|
||||||
|
setting_static = 'Назначаю {0} -> {1} / {2}{3}'
|
||||||
|
via_gw = ' через {0}'
|
||||||
|
current_config = 'Текущая конфигурация IPv4:'
|
||||||
|
update_available = 'доступно обновление ({0})'
|
||||||
|
lang_select = 'Select language / Выберите язык:'
|
||||||
|
lang_en = ' 1) English'
|
||||||
|
lang_ru = ' 2) Русский'
|
||||||
|
lang_invalid = 'Please enter 1 or 2 / Введите 1 или 2'
|
||||||
|
banner_subtitle = 'переключатель NIC IP/DHCP'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- First-run language prompt + config write ---
|
||||||
|
function Read-Language {
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host $STR.en.lang_select
|
||||||
|
Write-Host $STR.en.lang_en
|
||||||
|
Write-Host $STR.en.lang_ru
|
||||||
|
while ($true) {
|
||||||
|
$c = (Read-Host '>').Trim()
|
||||||
|
if ($c -eq '1') { return 'en' }
|
||||||
|
if ($c -eq '2') { return 'ru' }
|
||||||
|
Write-Host $STR.en.lang_invalid -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Write-DefaultConfig([string]$lang) {
|
||||||
|
$header = @"
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# netswitch configuration
|
||||||
|
#
|
||||||
|
# To change the interface language, edit the 'language' value below.
|
||||||
|
# Valid values: en, ru
|
||||||
|
#
|
||||||
|
# Чтобы сменить язык интерфейса, измените значение 'language' ниже.
|
||||||
|
# Допустимые значения: en, ru
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
[General]
|
||||||
|
language = $lang
|
||||||
|
"@
|
||||||
|
try { Set-Content -Path $ConfigPath -Value $header -Encoding UTF8 } catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
function Read-Config {
|
||||||
|
if (-not (Test-Path $ConfigPath)) {
|
||||||
|
$l = Read-Language
|
||||||
|
Write-DefaultConfig $l
|
||||||
|
return @{ language = $l }
|
||||||
|
}
|
||||||
|
$lang = 'en'
|
||||||
|
foreach ($line in (Get-Content $ConfigPath -ErrorAction SilentlyContinue)) {
|
||||||
|
if ($line -match '^\s*language\s*=\s*([a-zA-Z]+)\s*$') {
|
||||||
|
$v = $matches[1].ToLower()
|
||||||
|
if ($v -eq 'ru' -or $v -eq 'en') { $lang = $v }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return @{ language = $lang }
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = Read-Config
|
||||||
|
$L = $STR[$config.language]
|
||||||
|
|
||||||
|
# --- Update check (silent: returns latest tag if newer, else empty) ---
|
||||||
|
function Get-NetswitchUpdate {
|
||||||
|
try {
|
||||||
|
$url = "https://api.github.com/repos/$GithubRepo/releases/latest"
|
||||||
|
$r = Invoke-RestMethod -Uri $url -TimeoutSec 3 -Headers @{ 'User-Agent' = "netswitch/$NetswitchVersion" }
|
||||||
|
$latest = ($r.tag_name -as [string]) -replace '^v',''
|
||||||
|
if (-not $latest) { return '' }
|
||||||
|
$toTuple = { param($s)
|
||||||
|
$parts = ($s -split '\.') | ForEach-Object {
|
||||||
|
$n = 0; [void][int]::TryParse($_, [ref]$n); $n
|
||||||
|
}
|
||||||
|
while ($parts.Count -lt 3) { $parts += 0 }
|
||||||
|
,$parts[0..2]
|
||||||
|
}
|
||||||
|
$LV = & $toTuple $latest
|
||||||
|
$CV = & $toTuple $NetswitchVersion
|
||||||
|
for ($i = 0; $i -lt 3; $i++) {
|
||||||
|
if ($LV[$i] -gt $CV[$i]) { return $r.tag_name }
|
||||||
|
if ($LV[$i] -lt $CV[$i]) { return '' }
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$latestTag = Get-NetswitchUpdate
|
||||||
|
|
||||||
|
# --- Banner ---
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host '==============================================' -ForegroundColor Cyan
|
||||||
|
Write-Host (" netswitch v$NetswitchVersion - " + $L.banner_subtitle) -ForegroundColor Cyan
|
||||||
|
Write-Host '==============================================' -ForegroundColor Cyan
|
||||||
|
if ($latestTag) {
|
||||||
|
$msg = ($L.update_available -f $latestTag)
|
||||||
|
$w = 0
|
||||||
|
try { $w = $Host.UI.RawUI.WindowSize.Width } catch { $w = 0 }
|
||||||
|
if ($w -lt ($msg.Length + 2)) { $w = $msg.Length + 2 }
|
||||||
|
$pad = $w - $msg.Length - 1
|
||||||
|
Write-Host ((' ' * [Math]::Max(0, $pad)) + $msg) -ForegroundColor DarkGray
|
||||||
|
}
|
||||||
|
Write-Host ''
|
||||||
|
|
||||||
|
# --- Pick adapter (physical wired only) ---
|
||||||
|
$skipDescriptionPattern = 'VPN|Virtual|AnyConnect|TAP-|TUN-|Bluetooth|Loopback|WAN Miniport|Hyper-V|VMware|VirtualBox|WireGuard|OpenVPN|Tailscale|ZeroTier'
|
||||||
|
$skipMediaTypes = @('Native 802.11', 'Wireless WAN')
|
||||||
|
|
||||||
|
$adapters = @(Get-NetAdapter | Where-Object {
|
||||||
|
$_.Status -notin @('Disabled','Not Present') -and
|
||||||
|
-not $_.Virtual -and
|
||||||
|
$_.MediaType -notin $skipMediaTypes -and
|
||||||
|
$_.InterfaceDescription -notmatch $skipDescriptionPattern -and
|
||||||
|
$_.Name -notmatch $skipDescriptionPattern
|
||||||
|
} | Sort-Object ifIndex)
|
||||||
|
|
||||||
|
if ($adapters.Count -eq 0) {
|
||||||
|
Write-Host $L.no_adapters -ForegroundColor Red
|
||||||
|
Read-Host $L.press_enter; exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host $L.available_adapters
|
||||||
|
for ($i = 0; $i -lt $adapters.Count; $i++) {
|
||||||
|
$a = $adapters[$i]
|
||||||
|
$ips = (Get-NetIPAddress -InterfaceIndex $a.ifIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue |
|
||||||
|
Where-Object { $_.PrefixOrigin -ne 'WellKnown' }).IPAddress -join ', '
|
||||||
|
Write-Host (" {0}) [{1,-12}] {2} ({3}) {4}" -f ($i + 1), $a.Status, $a.Name, $a.InterfaceDescription, $ips)
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
$sel = (Read-Host $L.select_adapter).Trim()
|
||||||
|
$valid = ($sel -match '^\d+$') -and ([int]$sel -ge 1) -and ([int]$sel -le $adapters.Count)
|
||||||
|
if (-not $valid) { Write-Host $L.invalid_selection -ForegroundColor Red }
|
||||||
|
} while (-not $valid)
|
||||||
|
$nic = $adapters[[int]$sel - 1]
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host ($L.selected -f $nic.Name) -ForegroundColor Green
|
||||||
|
|
||||||
|
# --- Mode ---
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host $L.mode_header
|
||||||
|
Write-Host $L.mode_static
|
||||||
|
Write-Host $L.mode_dhcp
|
||||||
|
$modeChoice = Read-Host $L.mode_choice
|
||||||
|
if ([string]::IsNullOrWhiteSpace($modeChoice)) { $modeChoice = '1' }
|
||||||
|
|
||||||
|
if ($modeChoice.Trim() -eq '2') {
|
||||||
|
# --- DHCP ---
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host ($L.setting_dhcp -f $nic.Name) -ForegroundColor Yellow
|
||||||
|
$null = & netsh interface ipv4 set address name="$($nic.Name)" source=dhcp 2>&1
|
||||||
|
$null = & netsh interface ipv4 set dnsservers name="$($nic.Name)" source=dhcp 2>&1
|
||||||
|
Write-Host $L.done -ForegroundColor Green
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# --- Static ---
|
||||||
|
$ip = Read-Host $L.ip_prompt
|
||||||
|
if ([string]::IsNullOrWhiteSpace($ip)) { $ip = '10.10.10.1' }
|
||||||
|
|
||||||
|
$mask = Read-Host $L.mask_prompt
|
||||||
|
if ([string]::IsNullOrWhiteSpace($mask)) { $mask = '255.255.255.0' }
|
||||||
|
|
||||||
|
$gw = Read-Host $L.gw_prompt
|
||||||
|
|
||||||
|
$gwTail = if ([string]::IsNullOrWhiteSpace($gw)) { '' } else { ($L.via_gw -f $gw) }
|
||||||
|
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host ($L.setting_static -f $nic.Name, $ip, $mask, $gwTail) -ForegroundColor Yellow
|
||||||
|
|
||||||
|
if ([string]::IsNullOrWhiteSpace($gw)) {
|
||||||
|
$null = & netsh interface ipv4 set address name="$($nic.Name)" static $ip $mask 2>&1
|
||||||
|
} else {
|
||||||
|
$null = & netsh interface ipv4 set address name="$($nic.Name)" static $ip $mask $gw 2>&1
|
||||||
|
}
|
||||||
|
Write-Host $L.done -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- Show current state ---
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host $L.current_config -ForegroundColor Cyan
|
||||||
|
Get-NetIPAddress -InterfaceIndex $nic.ifIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue |
|
||||||
|
Where-Object { $_.PrefixOrigin -ne 'WellKnown' } |
|
||||||
|
Format-Table IPAddress, PrefixLength, PrefixOrigin -AutoSize
|
||||||
|
|
||||||
|
Read-Host $L.press_enter
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
# Regenerate assets/icon.ico for this project.
|
||||||
|
# Edit $Text / colors below and re-run.
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$Text = "NET",
|
||||||
|
[int[]]$ColorFrom = @(120, 220, 140),
|
||||||
|
[int[]]$ColorTo = @(20, 110, 60),
|
||||||
|
[string]$OutPath = "$PSScriptRoot\..\assets\icon.ico"
|
||||||
|
)
|
||||||
|
|
||||||
|
Add-Type -AssemblyName System.Drawing
|
||||||
|
|
||||||
|
$outDir = Split-Path $OutPath -Parent
|
||||||
|
if (-not (Test-Path $outDir)) { New-Item -ItemType Directory -Path $outDir -Force | Out-Null }
|
||||||
|
|
||||||
|
$bgFrom = [System.Drawing.Color]::FromArgb(255, $ColorFrom[0], $ColorFrom[1], $ColorFrom[2])
|
||||||
|
$bgTo = [System.Drawing.Color]::FromArgb(255, $ColorTo[0], $ColorTo[1], $ColorTo[2])
|
||||||
|
|
||||||
|
$sizes = 256, 128, 64, 48, 32, 16
|
||||||
|
$pngs = @()
|
||||||
|
foreach ($s in $sizes) {
|
||||||
|
$bmp = New-Object System.Drawing.Bitmap $s, $s
|
||||||
|
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
||||||
|
$g.SmoothingMode = 'AntiAlias'
|
||||||
|
$g.TextRenderingHint = 'AntiAliasGridFit'
|
||||||
|
|
||||||
|
$path = New-Object System.Drawing.Drawing2D.GraphicsPath
|
||||||
|
$r = $s - 2
|
||||||
|
$path.AddEllipse(1, 1, $r, $r)
|
||||||
|
$brush = New-Object System.Drawing.Drawing2D.PathGradientBrush($path)
|
||||||
|
$brush.CenterColor = $bgFrom
|
||||||
|
$brush.SurroundColors = @($bgTo)
|
||||||
|
$g.FillEllipse($brush, 1, 1, $r, $r)
|
||||||
|
|
||||||
|
$pen = New-Object System.Drawing.Pen ([System.Drawing.Color]::FromArgb(60, 0, 0, 0)), ([float]($s/64))
|
||||||
|
$g.DrawEllipse($pen, 1, 1, $r, $r)
|
||||||
|
|
||||||
|
$fontSize = [float]($s * 0.32)
|
||||||
|
$font = New-Object System.Drawing.Font "Segoe UI Black", $fontSize, ([System.Drawing.FontStyle]::Bold), ([System.Drawing.GraphicsUnit]::Pixel)
|
||||||
|
$sf = New-Object System.Drawing.StringFormat
|
||||||
|
$sf.Alignment = 'Center'; $sf.LineAlignment = 'Center'
|
||||||
|
$shadow = New-Object System.Drawing.SolidBrush ([System.Drawing.Color]::FromArgb(80, 0, 0, 0))
|
||||||
|
$g.DrawString($Text, $font, $shadow, [float]($s/2 + $s*0.02), [float]($s/2 + $s*0.02), $sf)
|
||||||
|
$g.DrawString($Text, $font, [System.Drawing.Brushes]::White, [float]($s/2), [float]($s/2), $sf)
|
||||||
|
$g.Dispose()
|
||||||
|
|
||||||
|
$ms = New-Object System.IO.MemoryStream
|
||||||
|
$bmp.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png)
|
||||||
|
$pngs += ,@{ size = $s; bytes = $ms.ToArray() }
|
||||||
|
$ms.Dispose(); $bmp.Dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
$fs = [System.IO.File]::Create($OutPath)
|
||||||
|
$bw = New-Object System.IO.BinaryWriter $fs
|
||||||
|
$bw.Write([uint16]0)
|
||||||
|
$bw.Write([uint16]1)
|
||||||
|
$bw.Write([uint16]$pngs.Count)
|
||||||
|
$offset = 6 + 16 * $pngs.Count
|
||||||
|
foreach ($p in $pngs) {
|
||||||
|
$w = if ($p.size -ge 256) { 0 } else { $p.size }
|
||||||
|
$bw.Write([byte]$w); $bw.Write([byte]$w)
|
||||||
|
$bw.Write([byte]0); $bw.Write([byte]0)
|
||||||
|
$bw.Write([uint16]1); $bw.Write([uint16]32)
|
||||||
|
$bw.Write([uint32]$p.bytes.Length); $bw.Write([uint32]$offset)
|
||||||
|
$offset += $p.bytes.Length
|
||||||
|
}
|
||||||
|
foreach ($p in $pngs) { $bw.Write($p.bytes) }
|
||||||
|
$bw.Close(); $fs.Close()
|
||||||
|
Write-Host "Wrote $OutPath"
|
||||||
Reference in New Issue
Block a user