This is FilterDataProvider class.
I tried https://www.vimeo.com & vimeo.com
This is the URL of demo. https://github.com/anismansuri63/MacFilter
class FilterDataProvider: NEFilterDataProvider {
override func startFilter(completionHandler: @escaping (Error?) -> Void) {
let exampleRule = NENetworkRule(
remoteNetwork: NWHostEndpoint(hostname: "https://www.vimeo.com/", port: "0"),
remotePrefix: 0,
localNetwork: nil,
localPrefix: 0,
protocol: .TCP,
direction: .any
)
let filterRule = NEFilterRule(networkRule: exampleRule, action: .drop)
let filterSettings = NEFilterSettings(rules: [filterRule], defaultAction: .drop)
apply(filterSettings) { error in
if let applyError = error {
os_log("Failed to apply filter settings: %@", applyError.localizedDescription)
}
completionHandler(error)
}
}
override func stopFilter(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
completionHandler()
}
override func handleNewFlow(_ flow: NEFilterFlow) -> NEFilterNewFlowVerdict {
return .drop()
}
}