-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetwork.swift
More file actions
68 lines (50 loc) · 1.66 KB
/
Copy pathNetwork.swift
File metadata and controls
68 lines (50 loc) · 1.66 KB
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
//
// Network.swift
// Absinthe-iOS-X8
//
// Created by Mitchell Kahn on 1/16/17.
// Copyright © 2017 Ourglass. All rights reserved.
//
import Foundation
import SystemConfiguration
import NetUtils
class Network {
static func getWiFiInterface() -> Interface? {
let interfaces = Interface.allInterfaces()
for iface in interfaces {
if iface.name == "en0" && iface.family == .ipv4 {
return iface
}
}
return nil
}
static func currentSSIDs() -> [String] {
guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {
return []
}
return interfaceNames.flatMap { name in
guard let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String:AnyObject] else {
return nil
}
guard let ssid = info[kCNNetworkInfoKeySSID as String] as? String else {
return nil
}
return ssid
}
}
static func wifiSSID() -> String? {
return currentSSIDs().first
}
// Get IP address of OPIE from data
static func getIPAddressFromData(address: NSData) -> String? {
var ipAddress : String?
var sa = sockaddr()
address.getBytes(&sa, length: MemoryLayout<sockaddr>.size)
if Int32(sa.sa_family) == AF_INET {
var ip4 = sockaddr_in()
address.getBytes(&ip4, length: MemoryLayout<sockaddr_in>.size)
ipAddress = String(format: "%s", inet_ntoa(ip4.sin_addr))
}
return ipAddress
}
}