While it seems that this has been asked many times before, but there’s a nasty twist here…
First, I’m working on a desktop application which calls a webpage on the same local system. This web application then calls upon a second server (in the local network) and needs to pass it’s own IP address to the other server. Easy, of course: Request.ServerVariables("LOCAL_ADDR") and I’m done…
It won’t work in this case… The code for the local web application is written in classic ASP and almost every sourcefile is encrypted, thus I cannot modify it’s code. All I can fix is the global.asa file. In the Application_OnStart event of global.asa is the line Application("InternalIp") = "172.22.14.59" and indeed, that’s the local IP address, hard-coded… And this application setting is used in the rest of the code to refer to the IP address.
However, my IP address in our local network tends to change every day, so every day I need to modify global.asa to contain my new IP address. I could write a small application which will modify global.asa for me every day on startup but I’d rather see a solution where global.asa would be smart enough to detect this IP address itself!
Unfortunately, the IP address must be known on the start of the application, not at the start of the session, else I could have used Application("InternalIp") = Request.ServerVariables("LOCAL_ADDR") in the Session_OnStart event. Tried this, application crashed, so it won’t work.
But that line of code in Application_OnStart won’t work, since Request is unknown at that moment, thus that would crash too. (Tried it, didn’t work…)
So, my limitation is that I need to get the IP address within the Application_OnStart event of global.asa in a reliable way. And no, using DNS names don’t work either. (Tried that too, didn’t work.) What options do I have?
you could use the commandline (wscript.shell) and ipconfig?
or write your ip address in a textfile (with the help of another tool) and then read out that text file
you could also add an asp page to your application, call that asp page from your desktop application. on the new asp page you could everything you want (e.g. set the application var with the help of request.servervariables…) then at the end do a redirect to the “original” (encrypted) asp page…