I have two servers on the intranet, a database server and a web server. And let the network administrator map an external network IP to the Web server so that the external network and the internal network can be accessed at the same time. But this creates a problem. The Web server uses the relative address of the internal network to retrieve data. In this way, when accessing from the external network, the data cannot be obtained and only the frame can be displayed. If the database server is also mapped, the intranet will not be accessible, and I will not be able to debug it. If the two servers are combined into one, the running speed will be affected, and now the boss does not want to invest any more money in it, after all, it is just a demonstration. It can also be solved by moving the two machines to the laboratory's network computer room and connecting them directly to the external network. However, the network computer room is closed and has an access card, so I cannot go in and make changes frequently.
I thought about it carefully and felt that this problem should be solved by making a judgment. Just judge whether the accessed is the internal network IP or the external network IP, and perform the corresponding operation based on the judgment. After checking the information, I found that using JS is good, because the IP obtained by JS has One advantage is that it obtains the IP set by the local machine. If the computer is connected to the Internet through a LAN, then it obtains the computer's LAN IP, unlike Request in ASP, which obtains the IP of the computer connected to the Internet.
Code (copied from someone else, but you can refer to it :) )
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JS gets client IP</title>
</head>
<body>
<script type="text/javascript" language="javascript">
<!--
function GetLocalIPAddress()
{
var obj = null;
var rslt = "";
try
{
obj = new ActiveXObject("rcbdyctl.Setting");
rslt = obj.GetIPAddress;
obj = null;
}
catch(e)
{
//Exception occurs
}
return rslt;
}
document.write("Your IP is: " + GetLocalIPAddress());
//-->
</script>
</body>
</html>
It is said that warnings may appear during use, but this is just a test, it should not be a problem, haha :)