Click here to Skip to main content
15,910,878 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I want to write code which change ip address of the pc.
Actually I have developed a hardware for access control, so I need to run IIS on that hardware and need to change IP address and date time of that pc.

Please suggest how I do this.

Thanks in Advance.
Posted
Updated 5-Jul-11 19:21pm
v2

public void setIP(string ip_address, string subnet_mask)
  {
    ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
    ManagementObjectCollection objMOC = objMC.GetInstances();

    foreach (ManagementObject objMO in objMOC)
    {
    if ((bool)objMO["IPEnabled"])
    {
      try
      {
      ManagementBaseObject setIP;
      ManagementBaseObject newIP =
        objMO.GetMethodParameters("EnableStatic");

      newIP["IPAddress"] = new string[] { ip_address };
      newIP["SubnetMask"] = new string[] { subnet_mask };

      setIP = objMO.InvokeMethod("EnableStatic", newIP, null);
      }
      catch (Exception)
      {
      throw;
      }


    }
    }
  }
 
Share this answer
 
XML
<div id="server_details">
                        <dl>
                            <dt>Server time :</dt>
                            <dd><%= DateTime.Now.ToLongDateString() + " : " + DateTime.Now.ToLongTimeString() %></dd>
                        </dl>
                        <dl>
                            <dt>Login ip :</dt>
                            <dd><% = Page.Request.ServerVariables.Get("remote_addr") %></dd>
                        </dl>
                    </div>

write it on the source(Default.aspx) of page.
 
Share this answer
 
Comments
siddhai12 1-Aug-11 4:06am    
Dear surbhi,

Thanks a lot, it's working. :)
Shall I use this code for only IP setting.
thanks in advance.
SURBHI TYAGI 1-Aug-11 4:33am    
Your welcome.
But IP Setting means???
siddhai12 1-Aug-11 7:03am    
it means I want to pass only IP not subnet !
basically I want to write three functions
1.Setip(IPadd)
2.Setsubnet(subnet)
3.setgateway(gateway)
like this. :(
pls suggest.
Thanks in advance !

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