7 个解决方案
#1
获取到是很多例子,但是修改好象很少;
#2
Request.UserHostAddress 这个可以获取地址,关于修改我也想知道.
#3
搜索一下,肯定有一大堆
#4
难啊,变通一下吧
先写个批处理
@echo off
rem eth //eth 为网卡名称,可在网络连接中查询,如"本地链接"
set eth="本地链接"
rem ip //ip 为你想更改的IP
set ip=192.168.4.23
rem gw //gw 为网关地址
set gw=192.168.4.1
rem netmasks //netmasks 为子网掩码
set netmasks=255.255.255.192
echo 正在将本机IP更改到: %ip%
rem
if %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% > nul
if not %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% 1 > nul
echo.........................
echo 检查当前本机IP:
ipconfig
echo.........................
echo 成功将本机IP更改为%ip%!
pause
close
再通过才c#程序运行这个批处理来达到目的
先写个批处理
@echo off
rem eth //eth 为网卡名称,可在网络连接中查询,如"本地链接"
set eth="本地链接"
rem ip //ip 为你想更改的IP
set ip=192.168.4.23
rem gw //gw 为网关地址
set gw=192.168.4.1
rem netmasks //netmasks 为子网掩码
set netmasks=255.255.255.192
echo 正在将本机IP更改到: %ip%
rem
if %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% > nul
if not %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% 1 > nul
echo.........................
echo 检查当前本机IP:
ipconfig
echo.........................
echo 成功将本机IP更改为%ip%!
pause
close
再通过才c#程序运行这个批处理来达到目的
#5
获取服务器的IP地址方法以DNS法较为简单实用,如下:
using System.Net;
private void ButtonIP_Click(object sender, System.EventArgs e)
{
System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if ( addressList.Length>1)
{ TextLIP.Text = addressList[0].ToString();
TextSIP.Text = addressList[1].ToString();
}
else
{
TextLIP.Text = addressList[0].ToString();
TextSIP.Text = "没有可用的连接";
}
}
获取服务器的IP地址与MAC地址另一方法如下:
using System.Management;
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[]) MO["IPAddress"];
if(IPAddresses.Length > 0)
stringIP = IPAddresses[0];
TextIP.Text = stringIP.ToString();
}
}
获取客户端本机的IP地址相当简易,方法如下:
using System.Net;
TextIP.Text=Page.Request.UserHostAddress;
如要获取客户端本机的MAC地址就相对复杂些,得导入调用两个API,用ARP协议获取,但这样只能获取到同网段机器的MAC,对于跨网段的得利用IP扫描或cmd中nbtstat命令获取MAC地址。也可通过读取系统注册表值或WMI的数据库来获取。各位如有简易可行的好办法请留言告诉我。
using System.Net;
private void ButtonIP_Click(object sender, System.EventArgs e)
{
System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if ( addressList.Length>1)
{ TextLIP.Text = addressList[0].ToString();
TextSIP.Text = addressList[1].ToString();
}
else
{
TextLIP.Text = addressList[0].ToString();
TextSIP.Text = "没有可用的连接";
}
}
获取服务器的IP地址与MAC地址另一方法如下:
using System.Management;
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[]) MO["IPAddress"];
if(IPAddresses.Length > 0)
stringIP = IPAddresses[0];
TextIP.Text = stringIP.ToString();
}
}
获取客户端本机的IP地址相当简易,方法如下:
using System.Net;
TextIP.Text=Page.Request.UserHostAddress;
如要获取客户端本机的MAC地址就相对复杂些,得导入调用两个API,用ARP协议获取,但这样只能获取到同网段机器的MAC,对于跨网段的得利用IP扫描或cmd中nbtstat命令获取MAC地址。也可通过读取系统注册表值或WMI的数据库来获取。各位如有简易可行的好办法请留言告诉我。
#6
使用WMI数据库的类查询MAC可以找到系统中安装的每一个网络接口,并显示返回的IP和MAC信息,这种方法得到的IP/MAC信息应该是与从本机注册表中得到的是相同的.可以远程获取IP/SUBNET/MAC等信息,试过了可以.
using System;
using System.Management;
class WMIqueryIPMAC
{
public static void Main()
{
ManagementObjectSearcher query = new
ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'") ;
ManagementObjectCollection queryCollection = query.Get();
foreach( ManagementObject MO in queryCollection )
{
string[] addresses = (string[])MO["IPAddress"];
string[] subnets = (string[])MO["IPSubnet"];
string[] defaultgateways = (string[])MO["DefaultIPGateway"];
Console.WriteLine("Network Card: {0}", MO["Description"]);
Console.WriteLine("MAC Address: {0}", MO["MACAddress"]);
foreach(string ipaddress in addresses)
{
Console.WriteLine("IP Address: {0}", ipaddress);
}
foreach(string subnet in subnets)
{
Console.WriteLine("Subnet Mask: {0}", subnet);
}
foreach(string defaultgateway in defaultgateways)
{
Console.WriteLine("Gateway: {0}", defaultgateway);
}
}
}
}
using System;
using System.Management;
class WMIqueryIPMAC
{
public static void Main()
{
ManagementObjectSearcher query = new
ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'") ;
ManagementObjectCollection queryCollection = query.Get();
foreach( ManagementObject MO in queryCollection )
{
string[] addresses = (string[])MO["IPAddress"];
string[] subnets = (string[])MO["IPSubnet"];
string[] defaultgateways = (string[])MO["DefaultIPGateway"];
Console.WriteLine("Network Card: {0}", MO["Description"]);
Console.WriteLine("MAC Address: {0}", MO["MACAddress"]);
foreach(string ipaddress in addresses)
{
Console.WriteLine("IP Address: {0}", ipaddress);
}
foreach(string subnet in subnets)
{
Console.WriteLine("Subnet Mask: {0}", subnet);
}
foreach(string defaultgateway in defaultgateways)
{
Console.WriteLine("Gateway: {0}", defaultgateway);
}
}
}
}
#7
操作更改用楼上的批处理方法也可行.
#1
获取到是很多例子,但是修改好象很少;
#2
Request.UserHostAddress 这个可以获取地址,关于修改我也想知道.
#3
搜索一下,肯定有一大堆
#4
难啊,变通一下吧
先写个批处理
@echo off
rem eth //eth 为网卡名称,可在网络连接中查询,如"本地链接"
set eth="本地链接"
rem ip //ip 为你想更改的IP
set ip=192.168.4.23
rem gw //gw 为网关地址
set gw=192.168.4.1
rem netmasks //netmasks 为子网掩码
set netmasks=255.255.255.192
echo 正在将本机IP更改到: %ip%
rem
if %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% > nul
if not %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% 1 > nul
echo.........................
echo 检查当前本机IP:
ipconfig
echo.........................
echo 成功将本机IP更改为%ip%!
pause
close
再通过才c#程序运行这个批处理来达到目的
先写个批处理
@echo off
rem eth //eth 为网卡名称,可在网络连接中查询,如"本地链接"
set eth="本地链接"
rem ip //ip 为你想更改的IP
set ip=192.168.4.23
rem gw //gw 为网关地址
set gw=192.168.4.1
rem netmasks //netmasks 为子网掩码
set netmasks=255.255.255.192
echo 正在将本机IP更改到: %ip%
rem
if %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% > nul
if not %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% 1 > nul
echo.........................
echo 检查当前本机IP:
ipconfig
echo.........................
echo 成功将本机IP更改为%ip%!
pause
close
再通过才c#程序运行这个批处理来达到目的
#5
获取服务器的IP地址方法以DNS法较为简单实用,如下:
using System.Net;
private void ButtonIP_Click(object sender, System.EventArgs e)
{
System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if ( addressList.Length>1)
{ TextLIP.Text = addressList[0].ToString();
TextSIP.Text = addressList[1].ToString();
}
else
{
TextLIP.Text = addressList[0].ToString();
TextSIP.Text = "没有可用的连接";
}
}
获取服务器的IP地址与MAC地址另一方法如下:
using System.Management;
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[]) MO["IPAddress"];
if(IPAddresses.Length > 0)
stringIP = IPAddresses[0];
TextIP.Text = stringIP.ToString();
}
}
获取客户端本机的IP地址相当简易,方法如下:
using System.Net;
TextIP.Text=Page.Request.UserHostAddress;
如要获取客户端本机的MAC地址就相对复杂些,得导入调用两个API,用ARP协议获取,但这样只能获取到同网段机器的MAC,对于跨网段的得利用IP扫描或cmd中nbtstat命令获取MAC地址。也可通过读取系统注册表值或WMI的数据库来获取。各位如有简易可行的好办法请留言告诉我。
using System.Net;
private void ButtonIP_Click(object sender, System.EventArgs e)
{
System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if ( addressList.Length>1)
{ TextLIP.Text = addressList[0].ToString();
TextSIP.Text = addressList[1].ToString();
}
else
{
TextLIP.Text = addressList[0].ToString();
TextSIP.Text = "没有可用的连接";
}
}
获取服务器的IP地址与MAC地址另一方法如下:
using System.Management;
string stringMAC = "";
string stringIP = "";
ManagementClass MC = new ManagementClass "Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOC= MC.GetInstances();
foreach(ManagementObject MO in MOC)
{
if ((bool)MO["IPEnabled"] == true)
{
stringMAC += MO["MACAddress"].ToString();
TextMAC.Text = stringMAC.ToString();
string[] IPAddresses = (string[]) MO["IPAddress"];
if(IPAddresses.Length > 0)
stringIP = IPAddresses[0];
TextIP.Text = stringIP.ToString();
}
}
获取客户端本机的IP地址相当简易,方法如下:
using System.Net;
TextIP.Text=Page.Request.UserHostAddress;
如要获取客户端本机的MAC地址就相对复杂些,得导入调用两个API,用ARP协议获取,但这样只能获取到同网段机器的MAC,对于跨网段的得利用IP扫描或cmd中nbtstat命令获取MAC地址。也可通过读取系统注册表值或WMI的数据库来获取。各位如有简易可行的好办法请留言告诉我。
#6
使用WMI数据库的类查询MAC可以找到系统中安装的每一个网络接口,并显示返回的IP和MAC信息,这种方法得到的IP/MAC信息应该是与从本机注册表中得到的是相同的.可以远程获取IP/SUBNET/MAC等信息,试过了可以.
using System;
using System.Management;
class WMIqueryIPMAC
{
public static void Main()
{
ManagementObjectSearcher query = new
ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'") ;
ManagementObjectCollection queryCollection = query.Get();
foreach( ManagementObject MO in queryCollection )
{
string[] addresses = (string[])MO["IPAddress"];
string[] subnets = (string[])MO["IPSubnet"];
string[] defaultgateways = (string[])MO["DefaultIPGateway"];
Console.WriteLine("Network Card: {0}", MO["Description"]);
Console.WriteLine("MAC Address: {0}", MO["MACAddress"]);
foreach(string ipaddress in addresses)
{
Console.WriteLine("IP Address: {0}", ipaddress);
}
foreach(string subnet in subnets)
{
Console.WriteLine("Subnet Mask: {0}", subnet);
}
foreach(string defaultgateway in defaultgateways)
{
Console.WriteLine("Gateway: {0}", defaultgateway);
}
}
}
}
using System;
using System.Management;
class WMIqueryIPMAC
{
public static void Main()
{
ManagementObjectSearcher query = new
ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'") ;
ManagementObjectCollection queryCollection = query.Get();
foreach( ManagementObject MO in queryCollection )
{
string[] addresses = (string[])MO["IPAddress"];
string[] subnets = (string[])MO["IPSubnet"];
string[] defaultgateways = (string[])MO["DefaultIPGateway"];
Console.WriteLine("Network Card: {0}", MO["Description"]);
Console.WriteLine("MAC Address: {0}", MO["MACAddress"]);
foreach(string ipaddress in addresses)
{
Console.WriteLine("IP Address: {0}", ipaddress);
}
foreach(string subnet in subnets)
{
Console.WriteLine("Subnet Mask: {0}", subnet);
}
foreach(string defaultgateway in defaultgateways)
{
Console.WriteLine("Gateway: {0}", defaultgateway);
}
}
}
}
#7
操作更改用楼上的批处理方法也可行.