Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to be able to send the local IP address of a computer along with the headers when making requests to a website. Similar to the way you can get the _SERVER["REMOTE_ADDR"] in php, but the local ip (e.g. 192.168.100.1) This will be an intranet so the environment can be controlled. Anything can be installed on the computer, etc.

This will be on a Mac OS X computer. Hoping for both Safari AND Firefox. But would be open to using one one.

Does anyone know if this is possible? Thanks so much.

share|improve this question
add comment

1 Answer

I guess that calls for somehow adding an X-Forwarded-For header, like some proxy servers would do. But, though not an official standard, I wonder if it "allows" for IP addresses from a private range though.

If you can make your browsers use GlimmerBlocker proxy, then you can add such headers through a Modify Request rule:

  • Add a new Rule (optionally, first add a new Filter to store the Rule)
  • On the rule type pane, set Action to Modify Request
  • On the request pane add:

    gb.request.headers['X-Forwarded-For'] = '192.168.100.1';
  • Or, to use the actual local IP address, I assume:

    var myIp;
    for(var k in gb.network.interfaces){
      var x = gb.network.interfaces[k];
      if(!x.IPv4){
        continue;
      }
      for(var i in x.IPv4.addr){
        var ip = x.IPv4.addr[i];
        // An interface can have multiple IP addresses, but assume
        // it has just a single address which is not localhost:
        if(ip == "127.0.0.1"){
          continue;
        }
        myIp = ip;
        break;
      }
    }
    gb.request.headers['X-Forwarded-For'] = myIp;
    
  • Optionally, only apply the rule to certain hosts.

(I am also quite curious about the why of this question...)

share|improve this answer
    
Ahh yes. Doing this at the hardware level totally makes sense. I am going to investigate the current proxy and see what we can do. Thanks. As for the why.... this is for an intranet website. Based on the local IP fixed address (assigned based on mac address) we can get an idea of the location of the computer. Cheap and easy. –  Louis W Feb 24 '10 at 23:06
    
@Louis: so, an intranet with multiple routers? Or a web server in a different segment? In a simple intranet the browser would connect to the server using its local IP address, right? That would then simply end up in _SERVER["REMOTE_ADDR"] -- but I guess you tested and found some other address. (I changed the JavaScript; my first untested version was sending 127.0.0.1...) –  Arjan Feb 24 '10 at 23:12
    
Not sure about the setup of number of routers. I am not on site at the moment. I did test this locally (we have 1 router which assigns ips based on macaddr) and REMOTE_ADDR came up as our public facing IP (same for all computers). –  Louis W Feb 24 '10 at 23:19
1  
@Louis, if you're using a proxy right now then maybe all it takes is setting up the workstations to not use the existing proxy for local addresses? If the web server and workstations are plugged into the same router, then when not using any proxy I'd expect the workstations to reveal their local IP address to that server. (But I'm no network expert; if you know the exact setup then maybe asking at serverfault.com gives you an easier solution.) –  Arjan Feb 24 '10 at 23:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.