AppleScript application to slow network

I keep doing the same ipfw commands over and over. Enough of that, here is my first applescript application every. Probably filled with bugs and other scary things, and I’m probably not the first one to do this, but I think I’m the first to stick the source out there.

property FLUSH_TEXT : "Quit and flush"
property SET_TEXT : "Set speed"
 
-- be damn carefull what you input here, it will run as root
on ipfwLimit(bandwidth)
	my ipfwFlush()
 
	do shell script "ipfw pipe 1 config bw " & bandwidth & "KB" with administrator privileges
	do shell script "ipfw add 10 pipe 1 tcp from any 80 to me" with administrator privileges
	do shell script "ipfw add 11 pipe 1 tcp from me to any 80" with administrator privileges
end ipfwLimit
 
-- flush any ipfw rules
on ipfwFlush()
	do shell script "ipfw -f flush" with administrator privileges
end ipfwFlush
 
on main()
	set question to display dialog "Control your http traffic speed" buttons {FLUSH_TEXT, SET_TEXT} default button 2
	set answer to button returned of question
 
	if answer is equal to FLUSH_TEXT then
		my ipfwFlush()
	end if
 
	if answer is equal to SET_TEXT then
		set bandwidth_question to display dialog "Enter bandwidth in KB/s (don't do something stupid like entering \"; rm -rf /)" default answer "56"
		set bandwidth to text returned of bandwidth_question
 
		my ipfwLimit(bandwidth)
 
		my main()
	end if
end main
 
my main()
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">