feature: add get current dns function
This commit is contained in:
parent
3e6c937008
commit
c89490c559
@ -11,8 +11,8 @@ import Cocoa
|
||||
class ClashStatusTool {
|
||||
static func checkPortConfig(cfg: ClashConfig?) {
|
||||
guard let cfg = cfg else { return }
|
||||
Logger.log("checkPortConfig: \(cfg.port) \(cfg.socketPort)", level: .debug)
|
||||
if cfg.port == 0 || cfg.socketPort == 0 {
|
||||
Logger.log("checkPortConfig: \(cfg.port) \(cfg.socketPort)", level: .error)
|
||||
let alert = NSAlert()
|
||||
alert.messageText = NSLocalizedString("ClashX Start Error!", comment: "")
|
||||
alert.informativeText = NSLocalizedString("Ports Open Fail, Please try to restart ClashX", comment: "")
|
||||
|
@ -59,6 +59,7 @@ class NetworkChangeNotifier {
|
||||
}
|
||||
|
||||
@objc static func onWakeNote(note: NSNotification) {
|
||||
|
||||
NotificationCenter.default.post(name: .systemNetworkStatusIPUpdate, object: nil)
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
@ -88,19 +89,26 @@ class NetworkChangeNotifier {
|
||||
}
|
||||
|
||||
static func getPrimaryInterface() -> String? {
|
||||
let key: CFString
|
||||
let store: SCDynamicStore?
|
||||
let dict: [String: String]?
|
||||
|
||||
store = SCDynamicStoreCreate(nil, "ClashX" as CFString, nil, nil)
|
||||
let store = SCDynamicStoreCreate(nil, "ClashX" as CFString, nil, nil)
|
||||
if store == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
key = SCDynamicStoreKeyCreateNetworkGlobalEntity(nil, kSCDynamicStoreDomainState, kSCEntNetIPv4)
|
||||
dict = SCDynamicStoreCopyValue(store, key) as? [String: String]
|
||||
let key = SCDynamicStoreKeyCreateNetworkGlobalEntity(nil, kSCDynamicStoreDomainState, kSCEntNetIPv4)
|
||||
let dict = SCDynamicStoreCopyValue(store, key) as? [String: String]
|
||||
return dict?[kSCDynamicStorePropNetPrimaryInterface as String]
|
||||
}
|
||||
|
||||
static func getCurrentDns() -> [String] {
|
||||
let store = SCDynamicStoreCreate(nil, "ClashX" as CFString, nil, nil)
|
||||
if store == nil {
|
||||
return []
|
||||
}
|
||||
|
||||
let key = SCDynamicStoreKeyCreateNetworkGlobalEntity(nil, kSCDynamicStoreDomainState, kSCEntNetDNS)
|
||||
let dnsArr = SCDynamicStoreCopyValue(store, key) as? [String:[String]]
|
||||
return dnsArr?[kSCPropNetDNSServerAddresses as String] ?? []
|
||||
}
|
||||
|
||||
static func getPrimaryIPAddress(allowIPV6: Bool = false) -> String? {
|
||||
guard let primary = getPrimaryInterface() else {
|
||||
|
Loading…
Reference in New Issue
Block a user