Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using windows application with c#.net I want Get system ip address and strore the database

using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
.
.
.

string strClientIP;

string[] computer_name = System.Net.Dns.GetHostEntry(Process.ServerVariables["remote_addr"]).HostName.Split(new Char[] { '.' });

textBox1 .Text = strClientIP.ToString() + "[" + computer_name[0].ToString() + "]";


This is i got error

System.Diagnostics.Process' does not contain a definition for 'ServerVariables' how to slove this error
Posted

ServerVariables is a property of the System.Web dll.
It makes no sense in a Windows Application.

Based on your tag I'm not sure if this is a windows or web application, but if it is a web one, add a reference to the System.Web dll.
 
Share this answer
 
Comments
Member 8614787 2-Feb-12 1:59am    
Thanks For Reply

I am using windows application how to clear this problem if any alternate way using servervariable ( or) get the ip address i search so many sites but all r using only servervariable but this one i can't get it
Abhinav S 2-Feb-12 2:12am    
Im sure http://www.geekpedia.com/tutorial149_Get-the-IP-address-in-a-Windows-application.html will help you out.
Member 8614787 2-Feb-12 4:44am    
Hi sir,

Sory I have one more question in this code i display only my system ipaddress ok.how to display all system ipaddress (for ex:how many system nw working (4 or 5)just displsy all ipaddress)
Try this

To get the IP address of the local machine in C#,
using system.net namespace

From IPHostEntry class, we get the list in a string array.

using System.Net;

Private string GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();

IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);

IPAddress[] addr = ipEntry.AddressList;

return addr[addr.Length-1].ToString();

}


Thanks
SP
 
Share this answer
 
Comments
Member 8614787 2-Feb-12 4:00am    
sory for the long reply
This code id working Thanks for your reply
Thanks,
Sridhar Patnayak 2-Feb-12 4:25am    
you are welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900