Link to home
Start Free TrialLog in
Avatar of Yashy
YashyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Debugging script - will this output what I'm trying to do?

hi guys,

I'm trying to debug a pac file below. Now, what I want to know is if my browser will see the IP addresses below and the only way I can do this is by having an alert. I have put the 'alert' function below, however I don't know whether putting in 'myarray[]'will return a value?I merely need all of the IP addresses the script can see to be outputted in the logs.Does this look correct?

var myip;
myip = myIpAddressEx();
var myarray;
myarray = myip.split(";");
var j = myarray.length;
var i = 0;
for (i = 0;i<j; i++){
if (isInNetEx (myarray [i], "10.201.50.0/23") ||
   isInNetEx (myarray [i], "192.168.1.0/24"))
    return "PROXY 10.208.5.254:3128";

alert("my first Ip address" + myarray[0]);
alert("my second Ip address" + myarray [1]);

Thanks again
Yashy
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Try this to be sure

function getProxy() {
  var myip = myIpAddressEx();
  var myarray = myip.split(";");
  console.log("my Ip addresses",myarray);
  var j = myarray.length;
  for (var i = 0;i<j; i++){
    if (isInNetEx (myarray [i], "10.201.50.0/23") || isInNetEx (myarray [i], "192.168.1.0/24")) {
      return "PROXY 10.208.5.254:3128";  
    }
  }
  return "No proxy for "+myip+" found"
}

var proxy = getProxy();
console.log(proxy)

Open in new window

Avatar of Yashy

ASKER

Michel - thank you for responding so quickly.

Can I save what you have done above as a .pac file to test with?
You need to return the proxy in the pac file


function getProxy() {
  var myip = myIpAddressEx();
  var myarray = myip.split(";");
  console.log("my Ip addresses",myarray);
  var j = myarray.length;
  for (var i = 0;i<j; i++){
    if (isInNetEx (myarray [i], "10.201.50.0/23") || isInNetEx (myarray [i], "192.168.1.0/24")) {
      return "PROXY 10.208.5.254:3128";  
    }
  }
  return ""; // nothing
}

var proxy = getProxy();
console.log(proxy)
if (proxy) return proxy;
console.log("No proxy for "+myip+" found")

Open in new window

Avatar of Yashy

ASKER

So you mean this code you have written needs to go into it like something like this (below) or can it work as standalone like you have written it?:

function FindProxyForURL(url, host)

{
if (dnsDomainIs(host, ".contoso.co.uk") ||
        shExpMatch(host, "(*.contoso.co.uk|contoso.local)"))
        return "DIRECT";

function getProxy() {
  var myip = myIpAddressEx();
  var myarray = myip.split(";");
  console.log("my Ip addresses",myarray);
  var j = myarray.length;
  for (var i = 0;i<j; i++){
    if (isInNetEx (myarray [i], "10.201.50.0/23") || isInNetEx (myarray [i], "192.168.1.0/24")) {
      return "PROXY 10.208.5.254:3128";  
    }
  }
  return ""; // nothing
}

var proxy = getProxy();
console.log(proxy)
if (proxy) return proxy;
console.log("No proxy for "+myip+" found")

}
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Yashy

ASKER

Apologies from my side, sorry. I think your snippet is now missing in the last post;).
I took the code from the last post. Some of my previous code was irrelevant then
Avatar of Yashy

ASKER

Ah got you. I didn't see the 'console.log' section you just added. Thanks a lot for helping Michel.

You are welcome
Avatar of Yashy

ASKER

I did try, but unfortunately in the google chrome logs that I look at, there's no 'my ip addresses' in the events section of the .json logs I captured or any IP addresses being displayed sadly. I changed back to the alert function. But it's cool, there will be more questions:). 
Ok, I do not have any recent experience with PAC files