Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 30th, 2003, 08:43 PM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Find Own IP

Can anyone give me a pointer how can I use C# to enumerate or find out the IP address of the machine the code is running on?

Thanks much
Adi Kremer
 
Old August 31st, 2003, 02:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi!

If you are using C# for your ASP .NET application you can definately do something like...

Code:
string ip = Page.Request.ServerVariables["LOCAL_ADDR"];
In order to see all the keys in the collection you can do something like this

Code:
NameValueCollection variables = Page.Request.ServerVariables;
string[] keys = variables.AllKeys;
for(int i = 0; i < keys.Length; i++)
   Page.Response.Write(keys[i] + "<BR>");

I don't know too much about .NET applications. I am only doing ASP .NET in C#, so the above goes for ASP .NET.

Jacob.
 
Old August 31st, 2003, 12:54 PM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jacob,

Thanks for your reply. Unfortunately, I do want to use this as a part of a console utility... So if anyone has any idea how to enum the local IP address/s, that would be great.

Thanks again
 
Old September 1st, 2003, 01:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Try this code and extend it if you need to

IPHostEntry LocalHost = Dns.GetHostByName("");
LocalHost.AddressList[0].ToString();

The requiered classes are defined in System.Net
namespace.


Ankur Verma
.Net and C++ Specialist
Wiley Tech Support





Similar Threads
Thread Thread Starter Forum Replies Last Post
Find IP Address for .vbs file ticktack VB How-To 1 July 27th, 2007 12:58 PM
Find Country from IP? ccc_storage Classic ASP Professional 3 June 5th, 2005 10:49 AM
find if user /ip is connected ALEX_GRIM Classic ASP Professional 8 February 7th, 2005 02:36 AM
find if a user/ ip is connected ALEX_GRIM ASP.NET 1.0 and 1.1 Professional 6 February 4th, 2005 12:53 AM
How do i find Client IP sethumail2000 C# 0 January 27th, 2005 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.