-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathui_mac2ip.go
92 lines (85 loc) · 2.26 KB
/
ui_mac2ip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"fmt"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func newMAC2IPTab(w fyne.Window, adapters []adapter) fyne.CanvasObject {
// adapter select
adapterNames := adapterNames(adapters)
adapterEntry := widget.NewSelectEntry(adapterNames)
if len(adapterNames) > 0 {
adapterEntry.SetText(adapterNames[0])
}
// log pane
logPaneLabel.Hide()
logPane.Disable()
logPane.Hide()
// result box
ipEntry := widget.NewEntry()
var ipCopyButton *widget.Button
ipCopyButton = widget.NewButton("Copy to clipboard", func() {
w.Clipboard().SetContent(ipEntry.Text)
ipCopyButton.Disable()
ipCopyButton.SetText("Copied!")
logContent = fmt.Sprintf("[%s]\nCP: %s\n\n%s", time.Now().Format(logTimeFormat), ipEntry.Text, logContent)
logPane.SetText(logContent)
})
ipResult := container.NewVBox(
widget.NewLabel("IP address:"),
ipEntry,
ipCopyButton,
)
ipResult.Hide()
// address input and submit
macEntry := newEnterEntry()
macEntry.SetPlaceHolder("ex. 12:34:56:78:90:ab")
var resolveButton *widget.Button
resolveButton = widget.NewButton("Resolve", func() {
resolveButton.Disable()
resolveButton.SetText("Resolving...")
defer func() {
resolveButton.Enable()
resolveButton.SetText("Resolve")
}()
mac := macEntry.Text
ip, err := mac2ip(mac, findAdapter(adapters, adapterEntry.Text))
if err != nil {
ipEntry.SetText("ERROR: " + err.Error())
logContent = fmt.Sprintf("[%s]\n%s > ERROR\n\n%s", time.Now().Format(logTimeFormat), mac, logContent)
} else {
ipEntry.SetText(ip)
logContent = fmt.Sprintf("[%s]\n%s > %s\n\n%s", time.Now().Format(logTimeFormat), mac, ip, logContent)
}
logPane.SetText(logContent)
if logPane.Hidden {
logPaneLabel.Show()
logPane.Show()
}
ipCopyButton.SetText("Copy to clipboard")
ipCopyButton.Enable()
ipResult.Show()
})
macEntry.setOnEnter(resolveButton.OnTapped)
resolveButton.Disable()
macEntry.OnChanged = func(s string) {
if len(s) > 0 && macPattern.MatchString(s) {
resolveButton.Enable()
} else {
resolveButton.Disable()
}
}
// layout
return container.NewVBox(
widget.NewLabel("Target MAC address:"),
macEntry,
widget.NewLabel("Network adapter:"),
adapterEntry,
resolveButton,
ipResult,
logPaneLabel,
logPane,
)
}