(*
Set MTU © RickoKid 2008
Version 0.1
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
set resultList to {}
set curMTU to ""
set OSVer to (do shell script "sw_vers -productVersion")
set tigerSupport to false
set legacySupport to false
if OSVer contains "10.4" or OSVer contains "10.3" or OSVer contains "10.2" or OSVer contains "10.1" or OSVer contains "10.1" then
if OSVer contains "10.4" then
set tigerSupport to true
else
display dialog "This script has only been tested on Mac OS X 10.4 and above. You may encounter errors and/or crashes in earlier versions of Mac OS X" buttons {"OK"} default button "OK"
set legacySupport to true
end if
set interfaceList to {}
repeat with theInterface in words of (do shell script "ifconfig -lu")
if theInterface contains "lo0" then
set interfaceList to interfaceList & {"lo0 Loopback"}
else if theInterface contains "en1" then
set interfaceList to interfaceList & {"en1 (AirPort?)"}
else if theInterface contains "en" then
set interfaceList to interfaceList & {theInterface & " (Ethernet?)"}
else if theInterface contains "fw" then
set interfaceList to interfaceList & {theInterface & " (Firewire?)"}
else
set interfaceList to interfaceList & {theInterface}
end if
end repeat
else
-- set interfaceList to paragraphs of (do shell script "networksetup -listallhardwareports | grep -e 'Hardware Port:' | sed 's/^.*: //'")
tell application "System Events" to set interfaceList to name of every interface of network preferences
end if
set chosenInterface to choose from list interfaceList with prompt ¬
"Please select the network interface(s) you would like to set the MTU for (or just click OK to select all interfaces):" with title ¬
"Select Network Interface" with multiple selections allowed and empty selection allowed
if chosenInterface is not false then -- if something is chosen, but not if cancel is clicked.
if chosenInterface is {} then set chosenInterface to interfaceList
if (count of chosenInterface) is not 1 then
set AppleScript's text item delimiters to return
set newMTU to text returned of (display dialog "Please enter the new MTU value for these interfaces:" & return & return & chosenInterface with title "Set MTU" default answer curMTU)
end if
repeat with theInterface in chosenInterface
if legacySupport or tigerSupport then
set netid to word 1 of theInterface
else
set netid to (do shell script "networksetup -listallhardwareports | grep -A1 'Hardware Port: " & theInterface & "$'| tail -n1| sed 's/^.*: //'")
end if
if (count of chosenInterface) is 1 then
set curMTU to last word of (do shell script "ifconfig " & netid & " |grep mtu")
set newMTU to text returned of (display dialog "Please enter the new MTU value for " & theInterface & ":" with title "Set MTU" default answer curMTU)
end if
try
do shell script "ifconfig " & netid & " mtu " & newMTU with administrator privileges and password
--set theIP to the result
set resultList to resultList & {"" & theInterface & ":" & tab & "MTU set to " & newMTU & "."}
on error errorText
set resultList to resultList & {"" & theInterface & ":" & tab & "Failed to set MTU."}
-- display dialog ". Make sure you are connected to the network via " & theInterface & "." with title "DHCP Lookup failure" buttons {"OK"} cancel button "OK" default button "OK"
end try
-- display dialog "" & theInterface & " DHCP server: " & theIP buttons {"OK"} default button "OK" with icon 1
end repeat
set AppleScript's text item delimiters to return
if legacySupport then
display dialog (resultList as text) with title "Set MTU" buttons {"OK"} default button "OK"
else
display alert "Set MTU" as informational message (resultList as text) buttons {"OK"} default button "OK"
end if
end if