Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Bypass DNS timeouts in Safari via AppleScript Web Browsers
For some reason, Apple has given Safari very little patience in waiting for DNS queries -- it quite often gives up on a query and won't load a page, even though that page will load fine in Firefox or another browser. If you need to use Safari, though, you can use this script to look up the IP address of the site and load the page using that instead:
    Bypass DNS in current tab © RickoKid 2008
    Version 0.1
    This script was written to get around the annoying way that Safari
    gives up very easily when waiting for a DNS lookup, but command
    line DNS lookups still work fine.
    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
    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 <>.

tell application "Safari"
  set webURL to ""
  set webPath to "/"
  set currentTab to current tab of window 1
  if (name of currentTab is not "Untitled") then
    set webURL to URL of currentTab
    set failedWin to text of currentTab
    if failedWin contains "Safari can't open the page" then 
      set webURL to text ((offset of """ in failedWin) + 1) thru ((offset of """ in failedWin) - 1) of failedWin
  end if
  if webURL is equal to "" then set webURL to text returned of (display dialog "Website to visit (bypassing DNS)" default answer webURL)
  set webServer to webURL
  if webURL contains "//" then set webServer to text ((offset of "//" in webURL) + 2) thru -1 of webURL
  if webServer contains "/" then
    set webServer to text 1 thru ((offset of "/" in webServer) - 1) of webServer
    set webPath to text ((offset of webServer in webURL) + (length of webServer)) thru -1 of webURL
  end if
  set websiteIP to my nslookup(webServer)
  set newURL to ("http://" & websiteIP & webPath) as string
  log "webServer:" & webServer
  log "webPath:" & webPath
  log "websiteIP:" & websiteIP
  log "newURL:" & newURL
  set URL of currentTab to newURL
end tell

on nslookup(address)
  set rawResult to (do shell script "host " & address & "| head -n1")
  set AppleScript's text item delimiters to space
  set parts to text items of rawResult
  return last item of parts
end nslookup
The easiest way to use it is to add it to your Safari script menu (by putting the script file in your user's Library » Scripts » Applications » Safari folder; create the folder if necessary). You can then select it from the Scripts menu when you're trying to load a page that seems to be stuck.

Be warned, though, that sometimes the page still won't load due to virtual server redirections that happen silently when given a DNS name. (This script was originally posted in this entry on my blog.)
  • Currently 1.86 / 5
  You rated: 2 / 5 (7 votes cast)

Bypass DNS timeouts in Safari via AppleScript | 4 comments | Create New Account
Click here to return to the 'Bypass DNS timeouts in Safari via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Bypass DNS timeouts in Safari via AppleScript
Authored by: dbs on May 20, '08 07:53:29AM

Nice trick. You probably don't even need to change the URL in Safari after doing the host lookup, though. The result should now be cached and a simple reload should correctly resolve the domain to the IP.

[ Reply to This | # ]
Bypass DNS timeouts in Safari via AppleScript
Authored by: jediknil on May 20, '08 11:34:18AM

This is a bad idea; many sites are run on virtual hosting, which means multiple sites are hosted on the same IP address. These sites probably won't work with this method.

Of course, hopefully most sites won't have DNS timeouts, either...

[ Reply to This | # ]
Bypass DNS timeouts in Safari via AppleScript
Authored by: DrivingHome on May 21, '08 06:06:43AM

Could you provide more idiot proof instructions. I followed yours and nothing appears in safari menu after install.

Also, surely the virtual ip issue only applies to what you might call large sites - mny small ones wouldn't use virtual ips

[ Reply to This | # ]
Or just use a faster DNS server
Authored by: Lectrick on May 21, '08 11:25:22AM
I swear by OpenDNS which has some very easy-to-follow instructions for getting your computer or router to use it for name resolution (i recommend the router, so all the computers benefit). Once I set this up, websurfing went noticeably faster. You might not even need to use this hint if it works for you.

In /dev/null, no one can hear you scream

[ Reply to This | # ]