3

applescript icon Un script para manejar el Firewall

La verdad es que si combinamos un lanzador de aplicaciones como QuickSilver con unos cuantos scripts útiles, podemos obtener un ahorro de tiempo altamente considerable a la hora de realizar nuestras tareas más cotidianas.

El script que os dejo hoy lo ví en Mac OS X Hints, y es muy útil, eso sí, para tenerlo corriendo siempre. En función de la red a la que nos conectemos, activa o desactiva automáticamente el firewall, por lo que es muy útil si tenemos el mismo ordenador para empresa y casa, por ejemplo.

Os dejo el script tras el salto.Primero guarda esto en /Library/LaunchAgents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>com.yourcompany.autofirewall</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Scripts/yourcompany/autofirewall.sh</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>WatchPaths</key>
<array>
<string>/var/run/resolv.conf</string>
</array>
</dict>

Y luego esto en /Library/Scripts/Elnombrequequieras:

#!/bin/bash

#Written by Nate Walck and Clint Armstrong
#Liberty University 2009

#This Script will automatically enable or disable the firewall depending upon which network it is on.

#This function turns the firewall on or off, depending upon which state is desired.
#If the firwall is already in the state desired, the script will leave it in that state.

function firewall {
#Reads the current state of the firewall and stores it in variable fw
fw=$(defaults read /Library/Preferences/com.apple.alf globalstate)

#This compares the option passed to function firewall to its current state.
if [ "$1" != "$fw" ]
then
#If the option pased is different from current state, it changes it to the passed value.
defaults write /Library/Preferences/com.apple.alf globalstate -int $1
#For troubleshooting purposes, you can put in 'say $1' to see which state is being set.
fi
}

#Determines if resolv.conf exists.
if test -e /var/run/resolv.conf
then
#This stores the domain line of resolv.conf into variable NETWORK.
NETWORK=$(cat /var/run/resolv.conf | grep domain | awk '{print $2}')

#This case looks at $NETWORK for specific domains and runs commands accordingly
case "$NETWORK" in

#If on VPN, function firewall turns the firewall on.
vpn.yourcompany.com
firewall 1
;;

#On any other company domain, function firewall turns firewall off.
*.yourcompany.com)
firewall 0
;;

#On any other domain, function firewall turns firewall on.
*)
firewall 1
;;

esac

else
#If no network connection exists, function firewall turns the firewall on.
firewall 1

fi

</plist>

Noticias Relacionadas

Comenta esta noticia
3 comentarios
Puntua esta noticia
Me gustaNo me gusta (sin puntuar)
Etiquetas: , ,
Categoría: Apple, Mac OS X, Trucos

3 Comentarios

  1. [...] Un script para manejar el Firewall (0) [...]

    Tu valoración: Thumb up 0 Thumb down 0

  2. [...] Un script para manejar el Firewall (1) [...]

    Tu valoración: Thumb up 0 Thumb down 0

  3. [...] Un script para manejar el Firewall (2) [...]

    Tu valoración: Thumb up 0 Thumb down 0

¿Te ha parecido interesante la noticia? ¡Déjanos tu comentario!

Publicidad
Publicidad