Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>");
   }
Posted
Updated 6-Jan-18 20:31pm

1 solution

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...
 
Share this answer
 
Comments
Basil PP 7-Jan-18 2:33am    
this iis is running on local machine not in internet
Basil PP 7-Jan-18 3:01am    
i want to change local ipaddress on the machine.but the problem is when i running after hosting local iis then the ipaddress is not changing.when i run program directly from visual studio then the ipaddress is not changing.
Richard Deeming 9-Jan-18 13:48pm    
Your application pool is most likely running as a user which doesn't have permission to change the server's IP address.
Basil PP 7-Jan-18 3:01am    
sorry read this one like this
when i run program directly from visual studio then the ipaddress is changing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900