由于经常在不同的工作地点和家里工作,电脑的ip经常需要重新设置;
因此自制了一个ip地址设置器,方便在不同办公环境下的ip地址切换。用xml存储每个办公场所的ip、dns设置,于是winform的bin\debug下有了:
WindowsFormsApplication1.exe
setting.xml
这两个文件,期望能够把这两个文件合成一个exe文件,无需安装...
因此自制了一个ip地址设置器,方便在不同办公环境下的ip地址切换。用xml存储每个办公场所的ip、dns设置,于是winform的bin\debug下有了:
WindowsFormsApplication1.exe
setting.xml
这两个文件,期望能够把这两个文件合成一个exe文件,无需安装...
问题是我要把这两个文件一起复制给同事或网友去使用这个软件,显然是不好的体验;
我希望把exe文件和xml文件合成一个exe文件,这样使用起来方便!
>netsh interface ip set address
One or more essential parameters were not entered.
Verify the required parameters, and reenter them.
The syntax supplied for this command is not valid. Check help for the correct syntax.Usage: set address [name=]<string>
[[source=]dhcp|static]
[[address=]<IPv4 address>[/<integer>] [[mask=]<IPv4 mask>]
[[gateway=]<IPv4 address>|none [gwmetric=]<integer>]
[[type=]unicast|anycast]
[[subinterface=]<string>]
[[store=]active|persistent]Parameters: Tag Value
name - Interface name or index.
source - One of the following values:
dhcp: Enables DHCP for configuring IP addresses for
the specified interface.
static: Disables DHCP for configuring IP addresses for
the specified interface. This value must be
specified if an address or a gateway is being
configured.
address - IPv4 address to add or modify, optionally followed by
the subnet prefix length.
mask - The IP subnet mask for the specified IP address.
gateway - One of the following values:
<IPv4 address>: A specific default gateway for the
static IP address you are setting.
none: No default gateways are set. This is the default.
gwmetric - The metric for the default gateway. This field should
be set only if gateway is specified.
type - One of the following values:
unicast: Marks the address as a unicast address.
This is the default.
anycast: Marks the address as an anycast address.
subinterface - LUID of the subinterface on which the default gateway
exists. This parameter is only needed on interfaces
with multiple subinterfaces.
store - One of the following values:
active: Set only lasts until next boot.
persistent: Set is persistent. This is the default.Res: Used to enable or disable DHCP for IP address configuration.
Also removes any previous static IP addresses and default gateways,
and can add a new static IP address and default gateway.Examples: set address name="Local Area Connection" source=dhcp
set address "Local Area connection" static 10.0.0.9 255.0.0.0 10.0.0.1 1
直接在程序里每次启动的时候自动获取本机的IP和dns
这样不是就可以了吗?
你换个工作地方,程序 启动的时候会自动获取本机IP和dns
IPAddress[] addrIP = Dns.GetHostAddresses(Dns.GetHostName());//获取可以使用的本机ip
//localAddress = addrIP[0];
foreach (var ip in addrIP)
{
//判断是否为IPv4地址
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localAddress = ip;
break;
}
}
加个自定配置 IP 和DNS 不就行了