⚡ Make ip be uint32 instead of strings
This commit is contained in:
+14
-14
@@ -19,27 +19,27 @@ export enum MessageTopic {
|
||||
|
||||
export type WifiStatus = {
|
||||
status: number
|
||||
local_ip: string
|
||||
local_ip: number
|
||||
mac_address: string
|
||||
rssi: number
|
||||
ssid: string
|
||||
bssid: string
|
||||
channel: number
|
||||
subnet_mask: string
|
||||
gateway_ip: string
|
||||
dns_ip_1: string
|
||||
dns_ip_2?: string
|
||||
subnet_mask: number
|
||||
gateway_ip: number
|
||||
dns_ip_1: number
|
||||
dns_ip_2?: number
|
||||
}
|
||||
|
||||
export type KnownNetworkItem = {
|
||||
ssid: string
|
||||
password: string
|
||||
static_ip_config: boolean
|
||||
local_ip?: string
|
||||
subnet_mask?: string
|
||||
gateway_ip?: string
|
||||
dns_ip_1?: string
|
||||
dns_ip_2?: string
|
||||
local_ip?: number
|
||||
subnet_mask?: number
|
||||
gateway_ip?: number
|
||||
dns_ip_1?: number
|
||||
dns_ip_2?: number
|
||||
}
|
||||
|
||||
export type WifiSettings = {
|
||||
@@ -73,7 +73,7 @@ export type NetworkItem = {
|
||||
|
||||
export type ApStatus = {
|
||||
status: number
|
||||
ip_address: string
|
||||
ip_address: number
|
||||
mac_address: string
|
||||
station_num: number
|
||||
}
|
||||
@@ -85,9 +85,9 @@ export type ApSettings = {
|
||||
channel: number
|
||||
ssid_hidden: boolean
|
||||
max_clients: number
|
||||
local_ip: string
|
||||
gateway_ip: string
|
||||
subnet_mask: string
|
||||
local_ip: number
|
||||
gateway_ip: number
|
||||
subnet_mask: number
|
||||
}
|
||||
|
||||
export type Rssi = {
|
||||
|
||||
@@ -6,3 +6,4 @@ export * from './buffer-utilities'
|
||||
export * from './model-utilities'
|
||||
export * from './string-utilities'
|
||||
export * from './color-utilities'
|
||||
export * from './ip-utilities'
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
export function ipToUint32(ip: string): number {
|
||||
const parts = ip.split('.')
|
||||
if (parts.length !== 4) return 0
|
||||
return (
|
||||
(parseInt(parts[0], 10) |
|
||||
(parseInt(parts[1], 10) << 8) |
|
||||
(parseInt(parts[2], 10) << 16) |
|
||||
(parseInt(parts[3], 10) << 24)) >>>
|
||||
0
|
||||
)
|
||||
}
|
||||
|
||||
export function uint32ToIp(ip: number): string {
|
||||
return [ip & 0xff, (ip >>> 8) & 0xff, (ip >>> 16) & 0xff, (ip >>> 24) & 0xff].join('.')
|
||||
}
|
||||
|
||||
export function isValidIpString(ip: string | undefined): boolean {
|
||||
if (!ip) return false
|
||||
const regexExp =
|
||||
/\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b/
|
||||
return regexExp.test(ip)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user