DevEdge [developer.netscape.com] has a very good script.
However, there is no such thing as an "optimized" script for your needs. Do you need to recognize all browsers? Well, then it's important that many common browsers can identify themselves as any browser.
Browser sniffing is seldom very reliable. If possible, try to avoid it.
I pretty much agree with the post above 'DevEdge' but in addition to that info, try to do your script in a process that gets the best results. What I mean is identify the OS first with a java script, then 'if' WIN OS run a VB if not run another java script. In most cases a WIN OS is easier to sniff than Linux etc. What I have found in general is that people who surf with browsers that run on Linux OS almost always don't want their browser to be sniffed, you have to build a round-a-bout method to sniff the browser at site's entrance. Once you sniff the OS the rest is fairly straightforward. Well! if you want to get real technical and want to accommodate wireless devices and such you will need to work harder to create a sniffer.