In those cases, I've found a fairly effective verbal counter. It goes something like this: "Listen, Bob [assuming the client's name is Bob]. I don't want to mislead you here. I'd rather work up a proper estimate than throw out some number on the spot that might be incorrect. I want to do this the right way, for your benefit and mine."
If Bob presses you further, respond with "I've worked on similar projects in the past. Some have taken 2 days, and some have taken 10 days. It really depends on X, Y, and Z. I want to take a proper accounting of X, Y, and Z in this case, so that I'm not misleading you up front."
If pressed further: "Bob, obviously time is of the essence for you and for this project. I understand that, and I will do everything I can to ensure that I complete the project as quickly as possible. In the end, this will be much quicker if we get it right the first time. Give me a little bit of time to do some planning, and it'll save us a lot of time in the long run."
All of this is true, of course. It's better to aim twice and shoot once, as the saying goes. However, there will be clients or bosses who just won't accept this sort of conversation up front. It'll piss them off. So be it. FAR better to have a little bit of confrontation at the outset than a lot of confrontation later on (i.e., if you toss out a gut estimate and then have to crawl back and amend or delay it).
BTW: that was a great episode!
"If you ask Fred, “When will you be done?” have you asked for an estimate or a commitment? What does Fred think you asked for? If Fred says, “Two weeks from today,” has he given an estimate or a commitment? What might happen if you want a commitment and Fred thinks you want an estimate? What might happen if you want an estimate and Fred thinks you want a commitment? How could you make it crystal clear whether you’re asking for an estimate or for a commitment? How could you make it crystal clear whether Fred is giving an estimate or a commitment?"
Edit: I meant to add that Scotty obviously was a genius in many ways.
Lt. Commander Geordi La Forge: Look, Mr. Scott, I'd love to explain everything to you, but the Captain wants this spectrographic analysis done by 1300 hours.
Scotty: Do you mind a little advice? Starfleet captains are like children. They want everything right now and they want it their way. But the secret is to give them only what they need, not what they want.
Lt. Commander Geordi La Forge: Yeah, well, I told the Captain I'd have this analysis done in an hour.
Scotty: How long will it really take?
Lt. Commander Geordi La Forge: An hour!
Scotty: Oh, you didn't tell him how long it would really take, did ya?
Lt. Commander Geordi La Forge: Well, of course I did.
Scotty: Oh, laddie. You've got a lot to learn if you want people to think of you as a miracle worker.