how to implement VPN Kill Switch programatically in macOS

0down


votefavorite



I want to implement VPN killswitch programatically.I could enable and disable pf manually from terminal.But I cant do it from my App. For this I loaded pf.conf file with rules:

"block drop all\n" "pass inet proto udp from any to 224.0.0.0/4 keep state\n" "pass inet proto udp from 224.0.0.0/4 to any keep state\n" "pass inet from any to 255.255.255.255 flags S/SA keep state\n" "pass inet from 255.255.255.255 to any flags S/SA keep state\n" "pass on $active_interface proto tcp from any port 67:68 to any port 67:68 flags S/SA keep state\n" "pass on $active_interface proto udp from any port 67:68 to any port 67:68 keep state\n" "pass on $active_interface inet proto tcp from any to 109.201.137.13 flags S/SA keep state\n" "pass on $active_interface inet proto udp from any to 109.201.137.13 keep state\n" "pass on $VPN_interface all flags S/SA keep state\n"

and it works fine with "sudo pfctl -e" and "sudo pfctl -d" when vpn is connected.If VPN is disconnectd traffic will be blocked and user have to either connect to the von or disable the kill swich to avail the traffic.

For executing commnd from mac app I used previlege helper tool and I am getting 'PF enbled' and 'PF disabled' as per the pf commands in the console.But the traffic is blocked all the time.I am using swift for development

I was struggling with this by a week.Please help any one asp. Any help will be appreciated.Thanks in advance.

Posted on Feb 4, 2018 10:14 PM

Reply

Similar questions

1 reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

how to implement VPN Kill Switch programatically in macOS

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.