您的位置:首页 > 运维架构 > Shell

Mac OS X: 实用脚本程序(bash scripts)系列-12

2010-10-30 12:23 288 查看
 

这个是从其它网站复制的,打开Mac OS X 10.4, 10.5, 10.6内置的防火墙。

 

#!/bin/sh
# enable_firewall.sh
#
# Patrick Gallagher
# http://macadmincorner.com 
# Stealth Mode - Set to 0 to disable
# Stealth mode prevents machine from responding to ping requestst
# Be aware that this would prevent tools such as ARD from discovering
# the machine, though bonjour on the same subnet will still work

osversionlong=`sw_vers -productVersion`
osvers=${osversionlong:3:1}

# Check if this is being run by root
if [ "$(whoami)" != "root" ] ; then
echo "Must be root to run this command." >&2
exit 1
fi

# Enable firewall for Tiger
if [ $osvers -eq 4 ]; then
echo "Setting firewall on a ${osversionlong} machine"
/usr/bin/defaults write /Library/Preferences/com.apple.sharing.firewall state -bool YES
# UDP, change to 0 to disable
/usr/bin/defaults write /Library/Preferences/com.apple.sharing.firewall udpenabled  -int 1
# Stealth, change to 0 to disable
/usr/bin/defaults write /Library/Preferences/com.apple.sharing.firewall stealthenabled -int 1
/usr/libexec/FirewallTool
fi

# Enable firewall for Leopard or Snow Leopard
if [ $osvers -ge 5 ]; then
echo "Setting firewall on a ${osversionlong} machine"
# Globalstate - Set to 0 for off, 1 for on, 2 for "Block all incoming access"
/usr/bin/defaults write /Library/Preferences/com.apple.alf globalstate -int 1
/usr/bin/defaults write /Library/Preferences/com.apple.alf stealthenabled -int 1
fi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  bash 脚本 os 防火墙 tools