Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get machine ip when there is no DNS?

Status
Not open for further replies.

ankursaxena

Programmer
Sep 7, 2001
133
0
0
US
Hi I wanted to get the ip addr of my machine ( not 127.0.0.1) but whatever is assigned in the prvt network but i dont have a dns hocked for that.

Thanks
 
So what does the following return for you?
Code:
string strHostName;
			strHostName = System.Net.Dns.GetHostName();

			IPHostEntry ipEntry = System.Net.Dns.GetHostByName (strHostName);
			IPAddress [] addr = ipEntry.AddressList;
          
			for (int i = 0; i < addr.Length; i++)
			{
				System.Windows.Forms.MessageBox.Show("IP Address: " +  i + addr[i].ToString());
			}
For me it returns the correct IP that I have been assigned (not 127.0.0.1).

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
are you connected to any dns? or is your machine standalone and on no network or a private network?

Thanks for the code...
 
If you're not connected to a network, then pretty much by default your only interface will be "localhost" at 127.0.0.1

If you are connected to a network, but don't have DNS services, then you have a problem (aside from having to type in IP addresses to get anywhere, that is).

Try using the .Resolve method.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
are you connected to any dns? or is your machine standalone and on no network or a private network?
I'm not connected to a network - the IP address that it picks up for me is the one assigned by my ISP for my internet connection.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I'm not connected to a network - the IP address that it picks up for me is the one assigned by my ISP for my internet connection.
Uhh, yes you are connected to a network -- the internet. Via your ISP.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Yes sorry - I meant I wasn't connected to any local network.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top