设置IP地址和使用asp.net到服务器的日期时间 [英] Set IP address & Date Time to server using asp.net

查看:95
本文介绍了设置IP地址和使用asp.net到服务器的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我想编写更改PC的IP地址的代码.
实际上,我已经开发了用于访问控制的硬件,因此我需要在该硬件上运行IIS,并且需要更改该PC的IP地址和日期时间.

请建议我该怎么做.

在此先感谢.

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.

推荐答案

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;
      }


    }
    }
  }


<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>


将其写在页面的源代码(Default.aspx)上.


write it on the source(Default.aspx) of page.


这篇关于设置IP地址和使用asp.net到服务器的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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