简体   繁体   中英

javascript get my local LAN ip address

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 -- Ie install mod-rewrite on the server and create a rule which switches the traffic without a redirect to the right resource on the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM