add ip and mac addr

animated the changes
This commit is contained in:
neon443
2025-04-27 21:34:49 +01:00
parent 64a517333b
commit 9c68de0af0
19 changed files with 274 additions and 21 deletions

View File

@@ -1,6 +1,31 @@
{
"images" : [
{
"filename" : "IconLight.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "IconDark.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "tinted"
}
],
"filename" : "IconTint.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

View File

@@ -48,6 +48,24 @@ struct ContentView: View {
Image(systemName: "rectangle.and.pencil.and.ellipsis")
}
}
NavigationLink() {
IPView()
} label: {
HStack {
Text("IP Adresses")
Spacer()
Image(systemName: "network")
}
}
NavigationLink() {
MACView()
} label: {
HStack {
Text("MAC Adresses")
Spacer()
Image(systemName: "antenna.radiowaves.left.and.right")
}
}
}
.navigationTitle("RNG")
.navigationBarTitleDisplayMode(.inline)

View File

@@ -71,22 +71,25 @@ struct DiceView: View {
}
}
Text(String(result))
.font(.system(size: 50, weight: .bold))
.font(.system(size: 50))
.foregroundColor(.gray)
.frame(height: 40)
.contentTransition(.numericText())
Text(resultDescription)
.frame(height: 10)
.font(.system(size: 10))
Button {
generated = rngN6DieArr(dies: Int(dies))
displayDies = generated
displayMultiDieMode = multiDieMode
result = arrCombine(arr: generated, combineMode: multiDieMode)
resultDescription = describeResult(inp: displayDies, combineMode: multiDieMode)
withAnimation {
generated = rngN6DieArr(dies: Int(dies))
displayDies = generated
displayMultiDieMode = multiDieMode
result = arrCombine(arr: generated, combineMode: multiDieMode)
resultDescription = describeResult(inp: displayDies, combineMode: multiDieMode)
}
} label: {
Text("Generate")
.padding(.horizontal)
.font(.system(size: 25, weight: .bold))
.font(.system(size: 25))
}
.buttonStyle(BorderedProminentButtonStyle())
.cornerRadius(15)

63
RNG/IPView.swift Normal file
View File

@@ -0,0 +1,63 @@
//
// IPView.swift
// RNG
//
// Created by Nihaal Sharma on 09/01/2025.
//
import SwiftUI
struct IPView: View {
@State var ipType = 4
@State var ip: String = ""
var body: some View {
List {
Picker("IP Version", selection: $ipType) {
Text("IPv4").tag(4)
Text("IPv6").tag(6)
}
.pickerStyle(SegmentedPickerStyle())
Text(ip)
.contentTransition(.numericText())
}
Button {
withAnimation {
ip = generateIPv(ipType)
}
} label: {
Text("Generate")
.padding(.horizontal)
.font(.system(size: 25))
.monospaced()
}
.buttonStyle(BorderedProminentButtonStyle())
.cornerRadius(15)
.padding(.vertical)
}
}
func generateIPv(_ type: Int) -> String {
let randomNumber = Int.random(in: 0..<256)
let randomNumber2 = Int.random(in: 0..<256)
let randomNumber3 = Int.random(in: 0..<256)
let randomNumber4 = Int.random(in: 0..<256)
switch type {
case 4:
return "\(randomNumber).\(randomNumber2).\(randomNumber3).\(randomNumber4)"
case 6:
for _ in 0..<6 {
for _ in 0..<4 {
let randomChar = Int.random(in: 0..<10)
print(randomChar)
}
}
// eg: fd7a:115c:a1e0:0000:6501:6f07
return "unimplemenented"
default:
return ""
}
}
#Preview {
IPView()
}

122
RNG/MACView.swift Normal file
View File

@@ -0,0 +1,122 @@
//
// IPView.swift
// RNG
//
// Created by Nihaal Sharma on 09/01/2025.
//
import Foundation
import SwiftUI
struct MACView: View {
@State var mac: String = ""
@State var maclook: String = ""
var body: some View {
Button("test") {
mac = "1c:57:dc:7f:d4:ce"
Task {
maclook = await maclookup(mac)
}
}
List {
HStack {
Label("Vendor", systemImage: "building.2.fill")
Spacer()
Text(maclook)
.bold()
}
}
Text(mac)
.font(.system(size: 30))
.foregroundColor(.gray)
.frame(height: 40)
.contentTransition(.numericText())
.monospaced()
Button {
withAnimation {
mac = generateMAC()
}
Task {
maclook = await maclookup(mac)
}
} label: {
Text("Generate")
.padding(.horizontal)
.font(.system(size: 25))
.monospaced()
}
.buttonStyle(BorderedProminentButtonStyle())
.cornerRadius(15)
.padding(.vertical)
}
}
func generateMAC() -> String {
var output = ""
for _ in 0..<6 {
output.append(hex(Int.random(in: 0...15)).hex)
output.append(hex(rng(min: 0, max: 15)).hex)
output.append(":")
}
output.removeLast()
return output
}
func maclookup(_ mac: String) async -> String {
let url = URL(string: "https://api.macvendors.com/\(mac)")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
do {
let (data, _) = try await URLSession(configuration: .ephemeral).data(for: request)
let result = String(data: data, encoding: .utf8) ?? "Lookup Error"
if result.contains("{") {
let dict = try JSONDecoder().decode([String: [String: String]].self, from: data)
if let dict = dict["error"] {
print(dict["detail"] as Any)
}
}
return "sd"
} catch {
print(error.localizedDescription)
return "Lookup Error"
}
}
class hex {
@Published var hex: String
init(_ int: Int) {
switch int {
case 16...Int.max:
self.hex = "F"
case Int.min...(-1):
self.hex = "0"
case 10:
self.hex = "A"
case 11:
self.hex = "B"
case 12:
self.hex = "C"
case 13:
self.hex = "D"
case 14:
self.hex = "E"
case 15:
self.hex = "F"
case 0...15:
self.hex = "\(int)"
default:
self.hex = "0"
}
self.hex = self.hex.lowercased()
}
}
#Preview {
MACView()
}

View File

@@ -52,16 +52,19 @@ struct NumberView: View {
}
}
Text(generated)
.font(.system(size: 50, weight: .bold))
.font(.system(size: 50))
.foregroundColor(.gray)
.frame(height: 40)
.contentTransition(.numericText())
Button {
prevGen = generated
generated = rng3(min: low, max: high, exclude: exclude)
withAnimation {
prevGen = generated
generated = rng3(min: low, max: high, exclude: exclude)
}
} label: {
Text("Generate")
.padding(.horizontal)
.font(.system(size: 25, weight: .bold))
.font(.system(size: 25))
}
.buttonStyle(BorderedProminentButtonStyle())
.cornerRadius(15)

View File

@@ -59,16 +59,19 @@ struct PasswordView: View {
}
Text(String(generated))
.font(.system(size: 50, weight: .bold))
.font(.system(size: 50))
.foregroundColor(.gray)
.frame(height: 40)
.contentTransition(.numericText())
Button {
generated = genPass(selectdOpts: selectedOptions, len: (presetLen == -1 ? customLen : presetLen))
withAnimation {
generated = genPass(selectdOpts: selectedOptions, len: (presetLen == -1 ? customLen : presetLen))
}
} label: {
Text("Generate")
.padding(.horizontal)
.font(.system(size: 25, weight: .bold))
.font(.system(size: 25))
}
.buttonStyle(BorderedProminentButtonStyle())
.cornerRadius(15)