[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4212
  • Last Modified:

Configuring a proxy pac file (Java)

Hi All,

Were trying to write a pac file to accomplish the following
if the ip address is 192.168.10.0 with a mask of 255.255.255.0 or the ip address is 192.168.12.0 with a mask of 255.255.255.0 and the url is http or https then use the proxy (192.168.10.20 on port 8080) http proxy

if the ip address is 192.168.10.0 with a mask of 255.255.255.0 or the ip address is 192.168.12.0 with a mask of 255.255.255.0 and the url is ftp. then use the proxy (192.168.10.20 on port 1080) socks proxy

Ive guessed at the code below which obviously doesnt work. Could anyone please assist? Im sure the logic is OK its just the java Im not getting right.

TIA for any ideas


function FindProxyForURL(url, host)
{
if (          	(isInNet(myIpAddress(), "192.168.10.0", "255.255.255.0") ||
          	isInNet(myIpAddress(), "192.168.12.0", "255.255.255.0")) &&
		(shExpMatch(url, "http:*") ||
		shExpMatch(url, https:*"))
return "PROXY 192.168.10.20:8080;" 
 
else if (          	(isInNet(myIpAddress(), "192.168.10.0", "255.255.255.0") ||
          	isInNet(myIpAddress(), "192.168.12.0", "255.255.255.0")) &&
		(shExpMatch(url, "ftp.*"))
 
return "SOCKS 192.168.10.20:1080;"
else
return "DIRECT";
}

Open in new window

0
johnsit
Asked:
johnsit
  • 2
  • 2
  • 2
3 Solutions
 
ksivananthCommented:
for java apps, you need to specify them as system properties, for e.g.,

http.proxyHost (default: <none>)
http.proxyPort (default: 80 if http.proxyHost specified)
http.nonProxyHosts (default: <none>

check this, http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html
0
 
ksivananthCommented:
0
 
CEHJCommented:
Try the following:
var ip = myIpAddress();
var reAddress = /192\.168\.1[02]\..+/;
var reProtocolHttp = /https?:.+/;
var reProtocolFtp = /ftp:.+/;
 
if (reAddress.test(ip) && reProtocolHttp.test(url)) {
	return "PROXY 192.168.10.20:8080";
}
 
else if (reAddress.test(ip) && reProtocolFtp.test(url)) {
	return "SOCKS 192.168.10.20:1080";
}
else {
	return "DIRECT";
}

Open in new window

0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
johnsitAuthor Commented:
Hi all,

Thanks for the input and sorry for the delayed response.

The requirements changed and we ended up going with the following, i.e. send http via proxy and all else direct (since our proxy isnt that good :) )

Im going to leave the q open for a while for any comments then award points appropriately if thats OK with all?

function FindProxyForURL(url, host)
{
// variable strings to return
var proxy_yes = "PROXY 192.168.10.20:8080";
var proxy_no = "DIRECT";
// Exceptions for protocols that dont proxy well
if (shExpMatch(url, "https://*")) { return proxy_no; }
if (shExpMatch(url, "ftp://*")) { return proxy_no; }
// If on the following networks then use proxy
if (isInNet(myIpAddress(), "192.168.10.0", "255.255.255.0")){ return proxy_yes; }
if (isInNet(myIpAddress(), "192.168.12.0", "255.255.255.0")){ return proxy_yes; }
// Send everything else direct
else
return "DIRECT";
}

Open in new window

0
 
johnsitAuthor Commented:
No more comments!

Thanks for the help. Will award points accordingly to who I feel made the best contributions, hope thats OK.
0
 
CEHJCommented:
:-)
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now