fix vendor lookup

minor ui
This commit is contained in:
neon443
2025-04-28 19:57:03 +01:00
parent 9c68de0af0
commit b49957d54c
2 changed files with 24 additions and 21 deletions

View File

@@ -17,9 +17,13 @@ struct IPView: View {
Text("IPv6").tag(6) Text("IPv6").tag(6)
} }
.pickerStyle(SegmentedPickerStyle()) .pickerStyle(SegmentedPickerStyle())
Text(ip)
.contentTransition(.numericText())
} }
Text(ip)
.font(.system(size: 30))
.foregroundColor(.gray)
.frame(height: 40)
.contentTransition(.numericText())
.monospaced()
Button { Button {
withAnimation { withAnimation {
ip = generateIPv(ipType) ip = generateIPv(ipType)

View File

@@ -11,20 +11,18 @@ import SwiftUI
struct MACView: View { struct MACView: View {
@State var mac: String = "" @State var mac: String = ""
@State var maclook: String = "" @State var maclook: String = ""
@State var looking: Bool = false
var body: some View { var body: some View {
Button("test") {
mac = "1c:57:dc:7f:d4:ce"
Task {
maclook = await maclookup(mac)
}
}
List { List {
HStack { HStack {
Label("Vendor", systemImage: "building.2.fill") Label("Vendor", systemImage: "building.2.fill")
Spacer() Spacer()
Text(maclook) if looking {
.bold() ProgressView()
} else {
Text(maclook)
.bold()
}
} }
} }
@@ -39,7 +37,9 @@ struct MACView: View {
mac = generateMAC() mac = generateMAC()
} }
Task { Task {
looking = true
maclook = await maclookup(mac) maclook = await maclookup(mac)
looking = false
} }
} label: { } label: {
Text("Generate") Text("Generate")
@@ -55,11 +55,11 @@ struct MACView: View {
func generateMAC() -> String { func generateMAC() -> String {
var output = "" var output = ""
for _ in 0..<6 { for _ in 0..<6 {
output.append(hex(Int.random(in: 0...15)).hex) output.append(hex(Int.random(in: 0...15)).hex)
output.append(hex(rng(min: 0, max: 15)).hex) output.append(hex(rng(min: 0, max: 15)).hex)
output.append(":") output.append(":")
} }
output.removeLast() output.removeLast()
return output return output
} }
@@ -74,12 +74,11 @@ func maclookup(_ mac: String) async -> String {
let result = String(data: data, encoding: .utf8) ?? "Lookup Error" let result = String(data: data, encoding: .utf8) ?? "Lookup Error"
if result.contains("{") { if result.contains("{") {
let dict = try JSONDecoder().decode([String: [String: String]].self, from: data) let dict = try JSONDecoder().decode([String: [String: String]].self, from: data)
if let dict = dict["error"] { if let dict = dict["errors"] {
print(dict["detail"] as Any) return "\(dict["detail"]!)"
} }
} }
return result
return "sd"
} catch { } catch {
print(error.localizedDescription) print(error.localizedDescription)
return "Lookup Error" return "Lookup Error"
@@ -118,5 +117,5 @@ class hex {
} }
} }
#Preview { #Preview {
MACView() MACView()
} }