Modify wpad.dat to allow users to go direct to non-standard ports and to allow variables for the proxy server name

Posted on 2009-02-11
Last Modified: 2013-12-14
I have a proxy.pac file that I have implemented as a wpad.dat for auto configuration of the proxy client in my network.  

I would like to accomplish two additional tasks:

1. Can I send websites direct if they have a custom port, such as or

2. Can I substitute the proxy server with a variable to represent their local login server (I have 9 remote sites and want them to use the proxy at their location) i.e. var proxone=%logonserver%

function FindProxyForURL(url,host)


// set p1 and p2 to the 2 proxies

var p1=""

var p2=""

//find the 4th octet - if even, is p1/p2 else p2/p1

var myip=myIpAddress()

var ipbits=myip.split(".")

var myseg=parseInt(ipbits[3])

if(myseg==Math.floor(myseg/2)*2) {

var proxone=p1

var proxtwo=p2


else {

var proxone=p2

var proxtwo=p1


//if name has no dots, or is our domain, or starts 10., or if my

//current address does not start 10. don't use proxy

if(isPlainHostName(host) ||

dnsDomainIs(host,"") ||

myip.substring(0,9)!=="192.20.1." ||

host.substring(0,9)=="192.20.1." )



// alert("direct")

return "DIRECT";


else {

// alert("proxy")

return "PROXY "+proxone+":3128; PROXY "+proxtwo+":3128" ;



Open in new window

Question by:medlinis
    LVL 22

    Accepted Solution

    Check out this page ...

    This has some examples that show you how to check to see if a machine in within a particular subnet, which would allow you to do question 2 and it shows checking a URL to see if there is a port reference which would allow you to do question 1.

    You might want to see if you can parse the data from URL to obtain the port and then see if it is equal or not to 80 or 8080 (outside the normal range of port references) otherwise this could be used as a bypass of the proxy servers.

    Author Closing Comment

    This was exactly what I needed.  I have gotten all parts of the script working properly.

    Thanks for the help

    Author Comment

    One additional resource that I found extremely useful:


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
    Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now