Files
hInterfaceManager/hInterfaceManager.ps1

345 lines
15 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#Requires -RunAsAdministrator
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
# ── Renkler & Fontlar ────────────────────────────────────────────────────────
$clrBg = [System.Drawing.Color]::FromArgb(245, 245, 247)
$clrPanel = [System.Drawing.Color]::White
$clrHeaderBg = [System.Drawing.Color]::FromArgb(26, 26, 46)
$clrColHdr = [System.Drawing.Color]::FromArgb(228, 228, 235)
$clrStatusBg = [System.Drawing.Color]::FromArgb(240, 240, 245)
$clrEnable = [System.Drawing.Color]::FromArgb(39, 80, 10)
$clrEnableBg = [System.Drawing.Color]::FromArgb(220, 240, 210)
$clrDisable = [System.Drawing.Color]::FromArgb(121, 31, 31)
$clrDisableBg = [System.Drawing.Color]::FromArgb(250, 225, 225)
$fontMain = New-Object System.Drawing.Font("Segoe UI", 9)
$fontSmall = New-Object System.Drawing.Font("Segoe UI", 8)
$fontTitle = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold)
# ── Ana Form ─────────────────────────────────────────────────────────────────
$form = New-Object System.Windows.Forms.Form
$form.Text = "hOLOlu Ag Arayuzu Yoneticisi"
$form.Size = New-Object System.Drawing.Size(1010, 560)
$form.MinimumSize = New-Object System.Drawing.Size(800, 440)
$form.StartPosition = "CenterScreen"
$form.BackColor = $clrBg
$form.Font = $fontMain
$form.FormBorderStyle = "Sizable"
# ── TableLayoutPanel: 3 satir (baslik+sutun | liste | buton+status) ───────────
$tbl = New-Object System.Windows.Forms.TableLayoutPanel
$tbl.Dock = "Fill"
$tbl.ColumnCount = 1
$tbl.RowCount = 3
$tbl.Padding = New-Object System.Windows.Forms.Padding(0)
$tbl.Margin = New-Object System.Windows.Forms.Padding(0)
$null = $tbl.RowStyles.Add((New-Object System.Windows.Forms.RowStyle(
[System.Windows.Forms.SizeType]::Absolute, 72))) # Baslik (48) + Sutun hdr (24)
$null = $tbl.RowStyles.Add((New-Object System.Windows.Forms.RowStyle(
[System.Windows.Forms.SizeType]::Percent, 100))) # Liste (kalan alan)
$null = $tbl.RowStyles.Add((New-Object System.Windows.Forms.RowStyle(
[System.Windows.Forms.SizeType]::Absolute, 82))) # Butonlar (56) + Status (26)
$form.Controls.Add($tbl)
# ── SATIR 0: Baslik + Sutun basliklari ───────────────────────────────────────
$pnlTop = New-Object System.Windows.Forms.Panel
$pnlTop.Dock = "Fill"
$pnlTop.BackColor = $clrHeaderBg
$tbl.Controls.Add($pnlTop, 0, 0)
# Baslik
$lblTitle = New-Object System.Windows.Forms.Label
$lblTitle.Text = " hOLOlu Ag Arayuzu Yoneticisi"
$lblTitle.ForeColor = [System.Drawing.Color]::White
$lblTitle.Font = $fontTitle
$lblTitle.Location = New-Object System.Drawing.Point(0, 0)
$lblTitle.Size = New-Object System.Drawing.Size(580, 48)
$lblTitle.TextAlign = "MiddleLeft"
$pnlTop.Controls.Add($lblTitle)
$lblAdmin = New-Object System.Windows.Forms.Label
$lblAdmin.Text = "ADMIN"
$lblAdmin.ForeColor = [System.Drawing.Color]::FromArgb(100, 210, 90)
$lblAdmin.Font = $fontSmall
$lblAdmin.Location = New-Object System.Drawing.Point(630, 0)
$lblAdmin.Size = New-Object System.Drawing.Size(60, 48)
$lblAdmin.TextAlign = "MiddleCenter"
$pnlTop.Controls.Add($lblAdmin)
# Sutun basliklari
$pnlColHdr = New-Object System.Windows.Forms.Panel
$pnlColHdr.BackColor = $clrColHdr
$pnlColHdr.Location = New-Object System.Drawing.Point(0, 48)
$pnlColHdr.Size = New-Object System.Drawing.Size(700, 24)
$pnlColHdr.Anchor = "Top,Left,Right"
$pnlTop.Controls.Add($pnlColHdr)
foreach ($h in @(
@{T="Arayuz Adi"; L=6; W=130},
@{T="Aciklama"; L=138; W=195},
@{T="Durum"; L=335; W=80},
@{T="Tip"; L=417; W=75},
@{T="MAC"; L=494; W=125},
@{T="IPv4"; L=621; W=130},
@{T="IPv6"; L=753; W=235}
)) {
$lbl2 = New-Object System.Windows.Forms.Label
$lbl2.Text = $h.T
$lbl2.Font = $fontSmall
$lbl2.ForeColor = [System.Drawing.Color]::FromArgb(80, 80, 95)
$lbl2.Location = New-Object System.Drawing.Point($h.L, 4)
$lbl2.Size = New-Object System.Drawing.Size($h.W, 16)
$pnlColHdr.Controls.Add($lbl2)
}
$pnlTop.Add_Resize({
$pnlColHdr.Width = $pnlTop.Width
$lblAdmin.Left = $pnlTop.Width - 70
})
# ── SATIR 1: ListView ────────────────────────────────────────────────────────
$lv = New-Object System.Windows.Forms.ListView
$lv.Dock = "Fill"
$lv.View = "Details"
$lv.FullRowSelect = $true
$lv.GridLines = $true
$lv.BackColor = $clrPanel
$lv.BorderStyle = "None"
$lv.Font = $fontMain
$lv.MultiSelect = $false
$lv.HeaderStyle = "None"
$null = $lv.Columns.Add("Ad", 132)
$null = $lv.Columns.Add("Aciklama", 195)
$null = $lv.Columns.Add("Durum", 82)
$null = $lv.Columns.Add("Tip", 77)
$null = $lv.Columns.Add("MAC", 127)
$null = $lv.Columns.Add("IPv4", 132)
$null = $lv.Columns.Add("IPv6", 240)
$tbl.Controls.Add($lv, 0, 1)
# ── SATIR 2: Butonlar + Durum ─────────────────────────────────────────────────
$pnlBottom = New-Object System.Windows.Forms.Panel
$pnlBottom.Dock = "Fill"
$pnlBottom.BackColor = $clrPanel
$tbl.Controls.Add($pnlBottom, 0, 2)
function New-Btn($text, $bg, $fg, $x) {
$b = New-Object System.Windows.Forms.Button
$b.Text = $text
$b.BackColor = $bg
$b.ForeColor = $fg
$b.FlatStyle = "Flat"
$b.FlatAppearance.BorderColor = [System.Drawing.Color]::FromArgb(180,180,190)
$b.FlatAppearance.BorderSize = 1
$b.Font = $fontMain
$b.Size = New-Object System.Drawing.Size(155, 34)
$b.Location = New-Object System.Drawing.Point($x, 8)
$b.Cursor = "Hand"
return $b
}
$btnEnable = New-Btn "Etkinlestir" $clrEnableBg $clrEnable 12
$btnDisable = New-Btn "Devre Disi" $clrDisableBg $clrDisable 177
$btnRefresh = New-Btn "Yenile" $clrBg ([System.Drawing.Color]::FromArgb(50,50,60)) 342
$pnlBottom.Controls.AddRange(@($btnEnable, $btnDisable, $btnRefresh))
$lblStatus = New-Object System.Windows.Forms.Label
$lblStatus.Text = " Hazir..."
$lblStatus.Font = $fontSmall
$lblStatus.ForeColor = [System.Drawing.Color]::FromArgb(90, 90, 100)
$lblStatus.BackColor = $clrStatusBg
$lblStatus.Location = New-Object System.Drawing.Point(0, 56)
$lblStatus.Size = New-Object System.Drawing.Size(700, 26)
$lblStatus.TextAlign = "MiddleLeft"
$pnlBottom.Controls.Add($lblStatus)
$pnlBottom.Add_Resize({
$lblStatus.Width = $pnlBottom.Width
})
# ── Adapterleri yukle ─────────────────────────────────────────────────────────
function Load-Adapters {
$lv.BeginUpdate()
$lv.Items.Clear()
try { $adapters = Get-NetAdapter -IncludeHidden -ErrorAction Stop | Sort-Object Name }
catch { $adapters = Get-NetAdapter -ErrorAction SilentlyContinue | Sort-Object Name }
foreach ($a in $adapters) {
$status = switch ($a.Status) {
"Up" { "Etkin" }
"Disabled" { "Devre disi" }
"Disconnected" { "Bagli degil" }
"NotPresent" { "Yok" }
default { [string]$a.Status }
}
$type = switch -Wildcard ($a.InterfaceDescription) {
"*Wi-Fi*" { "Wi-Fi" }
"*Wireless*" { "Wi-Fi" }
"*Bluetooth*" { "Bluetooth" }
"*Hyper-V*" { "Hyper-V" }
"*Loopback*" { "Loopback" }
"*TAP*" { "VPN/TAP" }
"*WAN*" { "WAN" }
"*Tunnel*" { "Tunnel" }
"*miniport*" { "Miniport" }
default { "Ethernet" }
}
$mac = if ($a.MacAddress) { [string]$a.MacAddress } else { "-" }
# IP adreslerini al (sadece Up olan adapterlerde anlamli)
$ipv4 = "-"
$ipv6 = "-"
try {
$addrs = Get-NetIPAddress -InterfaceIndex $a.InterfaceIndex -ErrorAction SilentlyContinue
$v4list = $addrs | Where-Object { $_.AddressFamily -eq "IPv4" } |
Select-Object -ExpandProperty IPAddress
$v6list = $addrs | Where-Object { $_.AddressFamily -eq "IPv6" -and
$_.IPAddress -notlike "fe80*" } |
Select-Object -ExpandProperty IPAddress
# fe80 (link-local) adresler cok yer kaplıyor, ayri listele
$v6ll = $addrs | Where-Object { $_.AddressFamily -eq "IPv6" -and
$_.IPAddress -like "fe80*" } |
Select-Object -ExpandProperty IPAddress
if ($v4list) { $ipv4 = ($v4list -join ", ") }
$v6all = @()
if ($v6list) { $v6all += $v6list }
if ($v6ll) { $v6all += ($v6ll | ForEach-Object { "$_ (LL)" }) }
if ($v6all) { $ipv6 = ($v6all -join ", ") }
} catch { }
# ListViewItem olustur — SubItems string dizisi olarak ver
$row = New-Object System.Windows.Forms.ListViewItem([string]$a.Name)
$row.SubItems.Add([string]$a.InterfaceDescription) | Out-Null
$row.SubItems.Add([string]$status) | Out-Null
$row.SubItems.Add([string]$type) | Out-Null
$row.SubItems.Add([string]$mac) | Out-Null
$row.SubItems.Add([string]$ipv4) | Out-Null
$row.SubItems.Add([string]$ipv6) | Out-Null
$row.Tag = [string]$a.Name
$row.ForeColor = switch ($a.Status) {
"Up" { [System.Drawing.Color]::FromArgb(20, 90, 20) }
"Disabled" { [System.Drawing.Color]::FromArgb(160, 50, 50) }
default { [System.Drawing.Color]::FromArgb(110,110,120) }
}
$lv.Items.Add($row) | Out-Null
}
$lv.EndUpdate()
$lblStatus.Text = " $($adapters.Count) adapter listelendi | Admin yetkisiyle calisiyor"
}
# ── Secim degisince durum guncelle ────────────────────────────────────────────
$lv.Add_SelectedIndexChanged({
if ($lv.SelectedItems.Count -eq 0) { return }
$n = [string]$lv.SelectedItems[0].Tag
$a = Get-NetAdapter -Name $n -IncludeHidden -ErrorAction SilentlyContinue
if (-not $a) { return }
$s = switch ($a.Status) {
"Up" { "Etkin" }
"Disabled" { "Devre disi" }
"Disconnected" { "Bagli degil" }
default { [string]$a.Status }
}
$lblStatus.Text = " Secili: $n | $s | $([string]$a.InterfaceDescription)"
# Secili satirdaki IP degerlerini status bar'a ekle
$selItem = $lv.SelectedItems[0]
$ip4show = $selItem.SubItems[5].Text
$ip6show = $selItem.SubItems[6].Text
$ipPart = ""
if ($ip4show -ne "-") { $ipPart += " IPv4: $ip4show" }
if ($ip6show -ne "-") { $ipPart += " IPv6: $ip6show" }
$lblStatus.Text = " Secili: $n | $s$ipPart"
})
# ── Etkinlestir ───────────────────────────────────────────────────────────────
$btnEnable.Add_Click({
if ($lv.SelectedItems.Count -eq 0) {
[System.Windows.Forms.MessageBox]::Show(
"Lutfen bir adapter secin.", "Uyari",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Warning) | Out-Null
return
}
$n = [string]$lv.SelectedItems[0].Tag
$lblStatus.Text = " '$n' etkinlestiriliyor..."
$form.Refresh()
try {
Enable-NetAdapter -Name $n -Confirm:$false -ErrorAction Stop
Start-Sleep -Milliseconds 1200
Load-Adapters
[System.Windows.Forms.MessageBox]::Show(
"'$n' basariyla etkinlestirildi.", "Basarili",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information) | Out-Null
} catch {
[System.Windows.Forms.MessageBox]::Show(
"Hata: $($_.Exception.Message)", "Islem basarisiz",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error) | Out-Null
$lblStatus.Text = " Hata olustu."
}
})
# ── Devre disi birak ──────────────────────────────────────────────────────────
$btnDisable.Add_Click({
if ($lv.SelectedItems.Count -eq 0) {
[System.Windows.Forms.MessageBox]::Show(
"Lutfen bir adapter secin.", "Uyari",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Warning) | Out-Null
return
}
$n = [string]$lv.SelectedItems[0].Tag
$r = [System.Windows.Forms.MessageBox]::Show(
"'$n' devre disi birakilacak. Onayliyor musunuz?", "Onay",
[System.Windows.Forms.MessageBoxButtons]::YesNo,
[System.Windows.Forms.MessageBoxIcon]::Question)
if ($r -ne [System.Windows.Forms.DialogResult]::Yes) { return }
$lblStatus.Text = " '$n' devre disi birakiliyor..."
$form.Refresh()
try {
Disable-NetAdapter -Name $n -Confirm:$false -ErrorAction Stop
Start-Sleep -Milliseconds 1200
Load-Adapters
[System.Windows.Forms.MessageBox]::Show(
"'$n' basariyla devre disi birakildi.", "Basarili",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information) | Out-Null
} catch {
[System.Windows.Forms.MessageBox]::Show(
"Hata: $($_.Exception.Message)", "Islem basarisiz",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Error) | Out-Null
$lblStatus.Text = " Hata olustu."
}
})
# ── Yenile ────────────────────────────────────────────────────────────────────
$btnRefresh.Add_Click({
$lblStatus.Text = " Yenileniyor..."
$form.Refresh()
Load-Adapters
})
# ── Cift tiklama = toggle ─────────────────────────────────────────────────────
$lv.Add_DoubleClick({
if ($lv.SelectedItems.Count -eq 0) { return }
$n = [string]$lv.SelectedItems[0].Tag
$a = Get-NetAdapter -Name $n -IncludeHidden -ErrorAction SilentlyContinue
if (-not $a) { return }
if ($a.Status -eq "Up") { $btnDisable.PerformClick() }
else { $btnEnable.PerformClick() }
})
# ── Baslat ───────────────────────────────────────────────────────────────────
Load-Adapters
$form.Add_Shown({ $form.Activate() })
[System.Windows.Forms.Application]::Run($form)