isInNet()

True if the IP address of host is in the network pattern/mask. Resolves host via DNS if it is not an IP literal.

isInNet(host, pattern, mask)  →  boolean

Used in about 63% of the real PAC files in the PAC file statistics.

Pattern and mask are dotted IPv4 strings: isInNet(host, "10.0.0.0", "255.0.0.0"). When host is a name, the engine first resolves it and the script waits for the answer. Only the first call for a name sends a DNS query; repeats are answered from a cache, so ten calls for one name are not ten queries. The cost comes from different names and from a DNS server that does not answer (see DNS in PAC files). When host is already an IP address, nothing is looked up. Guard the call with an IP-address test such as /^\d+\.\d+\.\d+\.\d+$/.test(host) if you only want to match addresses written in the URL.

The engines agree only as long as the pattern and the mask are written as four decimal numbers. With a CIDR pattern, a short mask, leading zeros or a missing argument, pactester, the browsers and Windows give different answers, as the section below explains.

Example

if (/^\d+\.\d+\.\d+\.\d+$/.test(host) &&
    isInNet(host, "10.0.0.0", "255.0.0.0")) {
  return "DIRECT";
}

pactester and the browsers can disagree about isInNet

For a plain call such as isInNet(host, "10.0.0.0", "255.0.0.0") every engine agrees. With a network in CIDR form ("10.0.0.0/8"), a shortened or prefix-length mask, leading zeros, a missing argument or an upper-case host name, pactester (pacparser), Chrome and Edge, Firefox and Windows (WinHTTP) do not all return the same answer. A file that passes a pactester test can then send the internal network to the proxy in the browser. Write the network and the mask as four plain numbers each. Paste your file into the PAC file tester and switch between the Chromium, Firefox and pacparser profiles to see which answer each engine gives. The tester also flags the calls where the engines disagree.

Check how your own file behaves with the PAC file tester: switch the engine profile between Chromium, Firefox, pacparser and Windows and compare the trace. All engine differences are collected in pactester vs Chrome and Firefox.

Engine notes

EngineBehaviourSource
chromiumValidates pattern and mask; a non-literal first argument is resolved with dnsResolve and null gives false.lab, verified 2026-10-11
services/proxy_resolver/pac_js_library.h@cb6eb0e7
firefoxSame logic as Chromium (validates pattern and mask, resolves names); upper-case names resolve.lab, verified 2026-10-11
netwerk/base/ascii_pac_utils.js@3f73c528
pacparserKeeps the original Netscape helper without a check of pattern and mask, so some invalid calls are true where Chromium and Firefox return false.lab, verified 2026-10-11
src/pac_utils.h@v1.5.3
chromiumAn IPv4 address as first argument is compared without a lookup. A name is resolved with dnsResolve, so a repeat of the same name in one request is answered from the table of names already resolved, and after 20 different names isInNet returns false without asking.code, verified 2026-10-14
services/proxy_resolver/pac_js_library.h@155.0.8059.83; services/proxy_resolver/proxy_resolver_v8_tracing.cc@155.0.8059.83
firefoxAn IPv4 address as first argument is compared without a lookup. A name goes to the browser's DNS cache on every call; there is no table in the PAC engine.code, verified 2026-10-14
netwerk/base/ascii_pac_utils.js@FIREFOX_157_0_RELEASE; netwerk/base/ProxyAutoConfig.cpp
winhttp100 calls for one name in one run sent one DNS query; the Windows DNS cache answered the rest. When the DNS server does not answer, every call waits about 12 s again.lab, verified 2026-10-14
Windows 11 25H2
winhttpResolves host names (upper case too) and compares IPv4 only; "LOCALHOST" is in 127.0.0.0/8. No check of pattern or mask: a CIDR pattern gives false, a short mask or a prefix length such as "8" can give true, and leading zeros are read as octal. A failed lookup counts as 0.0.0.0, so isInNet(dnsResolve("nonexistent.invalid"), "0.0.0.0", "255.255.255.255") is true. A missing or extra argument raises an error.lab, verified 2026-10-11
Windows 11 25H2

Availability

Derived from each engine's vendored helper library plus its native bindings (see engines).
Functionchromium
<=51
chromium
>=52
firefox
all
pacparser
<=1.4.6
pacparser
>=1.5.1
winhttp
11-25H2
wininet
11-25H2
reference
all
isInNetyesyesyesyesyesyesyesyes

Related rules

Frequently asked questions

Can I use CIDR notation such as 10.0.0.0/8 in isInNet?

No. isInNet expects the network and the mask as four numbers each, isInNet(host, "10.0.0.0", "255.0.0.0"). With "10.0.0.0/8" Chrome, Edge and Firefox return false, while pactester can return true, so a pactester test does not catch the mistake. The tester at findproxyforurl.net/check/ flags it.

Why does isInNet return true in pactester but false in Chrome?

pactester uses pacparser, whose helper functions differ from those in Chrome and Firefox for unusual arguments such as a CIDR network or a short mask. Test the file in a browser engine profile as well, for example in the tester at findproxyforurl.net/check/.

Last updated: