بفرمائید این هم کد هایی که IP سیستم جاری را پیدا میکند.
http://www.codeproject.com/KB/IP/Net...nfo_in_C_.aspx
من از این کد تو پروژم استفاده کردم البته با کمی تغییر بصورت زیر :
string strip = string.Empty;
[DllImport("Iphlpapi.dll")]
public static extern uint GetAdaptersAddresses(uint Family, uint flags, IntPtr Reserved,
IntPtr PAdaptersAddresses, ref uint pOutBufLen);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public void x()
{
//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////پیدا کردن IP/////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
IntPtr PAdaptersAddresses = new IntPtr();
bool AdapterFound = false;
uint pOutLen = 100;
PAdaptersAddresses = Marshal.AllocHGlobal(100);
uint ret =
GetAdaptersAddresses(0, 0, (IntPtr)0, PAdaptersAddresses, ref pOutLen);
// if 111 error, use
if (ret == 111)
{
Marshal.FreeHGlobal(PAdaptersAddresses);
PAdaptersAddresses = Marshal.AllocHGlobal((int)pOutLen);
ret = GetAdaptersAddresses(0, 0, (IntPtr)0, PAdaptersAddresses, ref pOutLen);
}
IP_Adapter_Addresses adds = new IP_Adapter_Addresses();
IntPtr pTemp = PAdaptersAddresses;
IntPtr pTempIP = new IntPtr();
while (pTemp != (IntPtr)0)
{
Marshal.PtrToStructure(pTemp, adds);
string adapterName = Marshal.PtrToStringAnsi(adds.AdapterName);
string FriendlyName = Marshal.PtrToStringAuto(adds.FriendlyName);
string tmpString = string.Empty;
for (int i = 0; i < 6; i++)
{
tmpString += string.Format("{0:X2}", adds.PhysicalAddress[i]);
if (i < 5)
{
tmpString += ":";
}
}
RegistryKey theLocalMachine = Registry.LocalMachine;
RegistryKey theSystem
= theLocalMachine.OpenSubKey(@"SYSTEM\CurrentControl Set\Services\Tcpip\Parameters\Interfaces");
RegistryKey theInterfaceKey = theSystem.OpenSubKey(adapterName);
if (theInterfaceKey != null)
{
string DhcpIPAddress = (string)theInterfaceKey.GetValue("DhcpIPAddress");
// system is using DHCP
if (DhcpIPAddress != null)
{
string tArray = (string)
theInterfaceKey.GetValue("DhcpIPAddress", theInterfaceKey);
if (FriendlyName.ToString() == "Wireless Network Connection")
{
strip += "Network adapter: " + FriendlyName.ToString() + "\r\n";
strip += "IP Address: " + tArray + "\r\n";
strip += "MAC Address: " + tmpString + "\r\n\r\n";
AdapterFound = true;
}
}
else
{
string[] tArray = (string[])
theInterfaceKey.GetValue("IPAddress", theInterfaceKey);
//AdapterInfoTextBox.Text += "Network adapter: " + FriendlyName.ToString() + "\r\n";
//for (int Interface = 0; Interface < tArray.Length; Interface++)
//{
// AdapterInfoTextBox.Text += "IP Address: " + tArray[Interface] + "\r\n";
// AdapterFound = true;
//}
//AdapterInfoTextBox.Text += "MAC Address: " + tmpString + "\r\n\r\n";
for (int Interface = 0; Interface < tArray.Length; Interface++)
{
strip = "\\" + "\\" + tArray[Interface];
AdapterFound = true;
}
}
}
pTemp = adds.Next;
}
if (AdapterFound != true)
{
strip += "No network adapters configured/present\r\n";
}
}
#endregion
IP در صورت وجود در رشته strip قرار میگیره ، حالا شما می تونید بر اساس اون هر کاری می خوای بکنی.دوباره تاکید می کنم من کد را تغییر دادم تا اطلاعات اضافی را که به کارم نمی آمد حذف کنم برای همین آدرس منبع کد را برایتان گذاشتم تا شما از آن در صورتی که اطلاعات بیشتر می خواهید ، استفاده کنید.
حالا شما می توانید با نوشتن یک برنامه کوچک که شامل کد بالا می باشد در سرور IP آن را بدست آورید و آن را در دیتابیس ذخیره کنید ، حالا با برنامه اصلی خود در سمت کلاینت شما می توانید با متصل شدن به دیتابیس و IP سرور را داشته باشید.
در ضمن دیدن این برنامه ها هم خالی از لطف نیست:
http://www.codeproject.com/KB/IP/IpX...?display=Print
http://www.codeproject.com/KB/IP/oba...formation.aspx
http://www.codeguru.com/Csharp/Cshar...icle.php/c6041
http://www.csharp-examples.net/local-ip/
امیدوارم کمک کرده باشم.
موفق باشید.