javascript get my local LAN ip address - javascript

I have quite happily set up pac files using myIpAddress() as a function to resolve the local IP on my LAN to load balance my proxies.
I now need to use this function, or anything that works simply, to return the local ip so that I can change the content of my media server to deliver hq video to high bandwidth pcs while delivering lower quality to the area offices which are on a different subnet.
Searching has proved futile.
The outcome is to have something that allows a web page to display http://mediaserver/x to one ip range and http://mediaserver/y to another.
I really don't care what WAN address they have, it's an intranet.
My pac file works just fine.
What do I need to do to get the same functionality in a web script that will work on win32, OSX and sun machines?

There is no way that a machine locally can determine its own IP address as seen by another server. For example my Linux Laptop has 3 different valid IP addresses, and that is not including any NAT addresses which may be transiently assigned for external traffic. Getting Javascript to locally work out which one is "correct" is a futile task.
What you need is a redirect server (for example http://mediaserver/entrypoint-for-redirect) , which determine which IP address a request is coming from and then base on that redirect (HTTP-302) to the desired resource -- that being either http://mediaserver/x or y.
EDIT
As you are using apache, you may also be able to implement the same without a redirect using the mod-rewrite module -- I.e. install mod-rewrite on the server and create a rule which switches the traffic without a redirect to the right resource on the server.

Related

How to open an iframe link going through a VPN

I would like to embed on my website a german link which is free and open only to german public. If i open from another country i get "This show is not available in your country for legal reasons."
Now if use a VPN in the other country i get access to the link. My question is:
Is there any way to embed an iframe passing his link through a VPN simply using javascript or jquery?
Final result should be the filtered link visible on my website.
Thnx
Using a http proxy!
Limitation:
No cookies
Sessions are messed up
Some website are proxy detection
Self hosting only, regions limitation
Unfortunately, there is no proper technical way to get the information you want. If you invent some tests but those will have a very low correlation with the reality. So either you'll not catch those you want or you will have a larger number of false positives. Neither can be considered to make sense.
There is no difference between a request that has been routed through a VPN and one that has not. It's not practical to get an exhaustive list of VPN endpoint IP addresses, and many of them are shared with non-VPN users anyway.
Generating any kind of traffic backwards from Internet server in response to an incoming client (port scan or even a simple ping) is generally frowned upon. Or, in case of a port scan, it may be even worse for you, ex when the client lives behind a central corporate firewall, the worst of which is when the client comes from behind the central government network firewall pool...

Amazon cloudfront IP resolution by client

I have a webapp that uses a lot of images which are cached through CloudFront. Some users complain that the load time is excruciatingly slow, So I want to build a diagnostic page on the site that will do a speed test by loading a few images and reporting the time. I also want to report the users IP address (which I can easily get from php when they load the page), but I also want to show the IP address that they are getting for the cloudfront server.
I know that if I run:
dig subdomain.cloudfront.net
I get several IP addresses. If an app (browser, QT app, mobile app) is running simultaneous connections to subdomain.cloudfront.net, does it always use the first IP first and use the others only if it fails?
And is there any way from within the browser that I can get these IP addresses as they are from the client users system? It's my understanding that they will get a different list of IPs based on their IP address.
If this is not possible from within the browser, is there any type of request that I could send to the cloudfront server that would include it's IP address in the response?
does it always use the first IP first
Most modern DNS resolvers and authoritative servers will randomise the order of the IP addresses -- more precisely, the set of A records for a given domain name.
So, "first IP" really isn't deterministic at all.
and use the others only if it fails?
Obviously this is very browser-dependent. Most modern browsers do handle it by retrying the other IPs. I wouldn't count on it though.
is there any way from within the browser that I can get these IP addresses as they are from the client users system?
From Chrome devtools network panel, you can see the address that the browser connected to in the "Remote Address" field of a request. However, I'm not aware of any way to access that from Javascript on a page.
It's my understanding that they will get a different list of IPs based on their IP address.
Yes.
is there any type of request that I could send to the cloudfront server that would include it's IP address in the response?
Not that I know of. However, you might be able to reverse engineer the Via or X-Amz-Cf-Id response header? At a cursory glance, both are unintelligible to me after hex or base64 decoding.
That said, there is a trick that you might be able to use, i.e. that you could setup a URL prefix in your distribution that forwards the requests to your server running PHP. You then point your users to a URL that would result in a request that gets forwarded to your PHP script. In your PHP script, examine the X-Forwarded-For header, which should include a Cloudfront IP.

Putting Node.js/Socket.io Onto a Website

So I'm getting into working with node.js and socket.io to make real-time web games, but I'm running into some obstacles.
I've already figured out how to install node.js and socket.io on my computer, and I can run basic servers and open them through http://localhost:8888/.
But now what I don't understand, and there doesn't seem to be anything on the web that explains this, is how to get this onto a website. Obviously, someone else on the internet that enters that same URL isn't going to see the same thing as what's on my screen. How do I get this onto a webpage so that anyone that visits that URL accesses the server?
I tried opening the port and then using http://<my external IP>:8888 but that doesn't work. Some sources seem to say that I need to install something on the website, but I installed node.js on my computer through command prompt, so I don't understand how that would work on a website. I found instructions for Linux, but I'm running Windows.
What you need is a:
web server - to host your game. You can, for instance, rent an EC2 instance from Amazon and install there all software required (Node.js, database, ...) or go with PaaS (Platform as a Service) solution like Nodejitsu or Heroku where you'll be given Node.js out of the box.
domain - to register a human-readable name for your web serwer (like. www.my-game.com). Normally, once you get your server, it'll have some IP address assigned to it. Domain name is an alias for it, easier to type and remember. Similar to, as in your case, localhost is just an alias for an IP 127.0.0.1 (special address meaning local system).
Of course, another solution would be to host app on your local PC and set up your router to forward traffic from it's external IP to your PC (assuming your ISP assigned you public IP). But then you'll have to worry about your PC, router and internet link being always online. And it'd be way slower than when going with external, dedicated hosting.

Get JavaScript Geolocation of Hosting Device

I want the immense accuracy of coordinates returned with navigator.geolocation.getCurrentPosition but instead of the client machine's location, I want the hosting machine's. Any IP-based solution I have found is sorely lacking in exactness (to be expected).
Envision a "Find My iPhone"-type of service but for any device. You visit a certain URL where you are able to see wherever whatever on which you have placed this technology goes. Is there a way to expose such (I imagine low-level) information if I'm developing with Node.js or otherwise? Thanks!
Host machines are just computers running some server software; they don't necessarily know where they are. You could save location data on a specific server for a client to access, but there's no way (besides guessing based on the IP like you mentioned) that a client can figure out where a given server is physically located if the server doesn't tell it.

How to get local IP from Firefox extension code

I'm writing a Firefox extension that uses nsIServerSocket to listen for socket connections. I'm looking for a way for the extension code to programmatically learn the local network address of the machine running the Firefox extension. This information gets communicated to a client on the local network out-of-band such that it can open a socket connection to the extension.
My research into this has so far only turned up individuals wishing to find the ip address of loaded websites by way of DNS resolution or using Java applets) which won't be appropriate for a FF extension. The Mozilla Developer pages on the Geolocation API mentions:
"data is exchanged including WiFi Access Point data, an access token (similar to a 2 week cookie), and the user's IP address"
but does not indicate an API to access the user's IP address directly.
My only idea at this point is to invoke a local process using nsIProcess and parse the IP from there. This seems awfully hackish and would have to be handled on a per-OS basis. I.e. do I run ifconfig, netcfg, ipconfig? With what args?
Is anyone aware of a better solution?
You use nsIDNSService interface here as well - it has a myHostName property that can be resolved:
var dns = Components.classes["#mozilla.org/network/dns-service;1"]
.getService(Components.interfaces.nsIDNSService);
var myName = dns.myHostName;
var record = dns.resolve(myName, 0);
while (record.hasMore())
alert(record.getNextAddrAsString());
You should expect it to produce multiple addresses and not all of them will be valid - even for the local network you will get at least two addresses (IPv6 and IPv4), in addition to that you might get a Teredo address, addresses from virtual adapters installed by VMWare & Co. and more.
I'd bet that the IP address mentioned in the Geolocation API is not the local computer's IP address. I mean, where in the world is 192.168.0.100, hmm? It's just not a useful piece of information, in general.
Since you're dealing with a local network, could you set up a small web page that just prints out the client's address? Then you could learn your IP by requesting that web page.

Categories