Skip to content

Instantly share code, notes, and snippets.

@sgonyea
Created July 29, 2012 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgonyea/3202098 to your computer and use it in GitHub Desktop.
Save sgonyea/3202098 to your computer and use it in GitHub Desktop.
Renews your DHCP Lease every 30-seconds, until an IP Address is assigned. Fight crappy WAPs!
#!/usr/bin/env ruby
# I believe 'en1' is the default WiFi device name on Mac OS X. It's what mine is set to.
def device; @device ||= ARGV[0] || "en1" end
def ip_set?
ip = `ipconfig getifaddr #{device}`
return false if ip.empty?
return false if ip.start_with?("169")
return true
end
def renew_dhcp_until_ip
until ip_set?
# Reset the IP
`sudo ipconfig set #{device} BOOTP`
`sudo ipconfig set #{device} DHCP`
sleep 30
end
`say 'Hey! You! You have an IP now! Z O M and G!'`
end
renew_dhcp_until_ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment