Wince中修改IP位址而無需重啟

2021-06-18 19:50:21 字數 2229 閱讀 1308

namespace utitlity.windows

\parms\tcpip";

/**

/// ip位址登錄檔項名稱

///

private const string ipaddressitem = "ipaddress";

/**

/// 子網掩碼的登錄檔項名稱

///

private const string subnetmaskitem = "subnetmask";

/**

/// 預設閘道器的登錄檔項名稱

///

private const string defaultgatewayitem = "defaultgageway";

/**

/// 乙太網卡的裝置檔名稱

///

private const string ethercardfilename = "nds0:";

/**

/// 乙太網卡的名稱

///

private static string ethercardname = string.empty;

/**

/// 儲存真實的乙太網卡ip位址資訊的登錄檔節點

///

private static string realtcpipregkeyname = string.empty;

/**

/// 在登錄檔中對ip資訊進行修改後,禁用網絡卡然後重啟網絡卡以應用修改

///

// send the device command.

if (deviceiocontrol(hndis, ioctl_ndis_rebind_adapter, ethercardname, ethercardname.length * 2 + 2, null, 0, 0, 0) == 0)

closehandle(hndis);

return true;

}/**

/// 獲取子網掩碼

///

///

public static string getsubnetmask()

/**

/// 設定子網掩碼

///

///

///

public static bool setsubnetmask(string subnetmask)

return setregvalue(subnetmaskitem, subnetmask);

}/**

/// 獲取ip位址

///

///

public static string getipaddress()

/**

/// 設定ip位址

///

///

public static bool setipaddress(string ip)

/**

/// 獲得網絡卡的名稱

///

///

private static string getethercardname()

if (deviceiocontrol2(filehandle, ioctl_ndis_get_adapter_names, null, 0, names, 255, ref bytes, 0) == 0)

int index = names.indexof('\0');

string result = names.substring(0, index);

return result;

}/**

/// 獲取注刪表項的值

///

private static string getregvalue(string regitemname, string defaultvalue)

if (!string.isnullorempty(ethercardname))

if(value.gettype() == typeof(string))}}

catch (exception)

}return defaultvalue;

}/**

/// 設定登錄檔項的值

///

private static bool setregvalue(string regitemname, string value)

trycatch (exception)}}

使用方法如下:

WinCE下重新設定IP位址無需重新啟動

include bool setipaddress cstring m strip,cstring m strmask,cstring m strgateway get list of adapter names if deviceiocontrol m hfilehandle,ioctl ndis...

修改Ip位址

臨時ip管理 ifconfig 網絡卡名 自己要設定的ip root fengjunhong fjh ifconfig ens33 192.168.1.120 重啟網路 centos7.x root fengjunhong fjh systemctl restart network centos6....

VMware中nginx修改ip位址

修改虛擬機器 nginx的ip位址 本地hosts檔案修改 各個網域名稱要指向你虛擬機器的ip 127.0.0.1 image.b2c.com 本地連線 192.168.124.132 image.b2c.com 虛擬機器連線 c windowssystem32driversetc 本地nginx....