C#Web应用程序中的IP地址更改 [英] IP address change in C# web application

查看:77
本文介绍了C#Web应用程序中的IP地址更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用这段代码以编程方式更改静态IP地址。当我在visual studio上运行此应用程序时,ip地址正在改变但是当我在iis服务器上托管此应用程序时,ip地址没有改变。但两者都是它们在执行过程中不会产生任何错误。



plz帮我解决这个问题。



< b>我尝试了什么:



I have used this code to change the static ip address programatically.when i run this application on visual studio then the ip address is changing but when i host this application on iis server then the ip address is not changing.but both of them does not produce any error during execution.

plz help me to solve this problem.

What I have tried:

protected void Button1_Click(object sender, EventArgs e)
   {

       //setIP1("10.10.28.30", "255.255.255.0", "10.10.28.1");
     //  return;

       ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
       ManagementObjectCollection objMOC = objMC.GetInstances();

       Response.Write("<table>");
       int x=1;
       foreach (ManagementObject objMO in objMOC)
       {

           Response.Write("<tr><td>" + x.ToString() + "</td><td>");
           Response.Write(objMO.ToString());
           Response.Write("</td><td>");
           Response.Write(objMO["IPEnabled"].ToString());
           Response.Write("</td></tr>");
         //  Response.Write("</tr>");
          // txtObjvalue.Text = objMO["IPEnabled"].ToString();
          // Response.Write(objMO["IPEnabled"].ToString() + "<br />");
           x++;
           if ((bool)objMO["IPEnabled"])
           {

               ManagementBaseObject setIP;
               ManagementBaseObject newIP =
                   objMO.GetMethodParameters("EnableStatic");

               newIP["IPAddress"] = new string[] { ipa.Text.Trim() };
               newIP["SubnetMask"] = new string[] { subnet.Text.Trim() };

               setIP = objMO.InvokeMethod("EnableStatic", newIP, null);
           }

       }
       Response.Write("</table>");
   }

推荐答案

可以更改本地IP地址(如果本地DHCP服务器允许)但是更改互联网上的IP地址并不那么简单:它们由运行IIS的托管服务分配,您可以通过ICAN服务器和DNS查找服务器在互联网上映射到您的网站时更改该地址。将myDomain.com翻译为123.456.789.0



您无法自行更改您的互联网IP地址:不在客户端(由客户的ISP分配) )或在服务器(它是主机服务决定)。



想一想:如果可以,连接会立即失败,因为数据包会解决你的服务器完全会在其他地方结束......
Changing local IP addresses is possible (if the local DHCP server allows it) but changing IP addresses on the internet is not so simple: They are assigned by the hosting service that IIS is running under and you can;t change that address as it is "mapped" to your website across the internet via ICAN servers and DNS lookup servers which translate "myDomain.com" to "123.456.789.0"

You cannot change your internet IP address yourself: not at the client (where it is assigned by the client's ISP) or at the server (where it's the hosting service that decides).

Think about it: if you could, the connection would immediately fail, as the packets addresses to your server would end up somewhere else completely...


这篇关于C#Web应用程序中的IP地址更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆