How to get IP address/name of the machine

Hi all,

I have a requirement to find out IP address/name of the machine to which a given windows user is currently logged on. Is that possible with C#? If anyone has came across sample code please guide me to appropriate resource. 


Blog: SEO Articles

Website: Search Engine Ranking
0
bhav27
2/4/2009 4:50:04 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

8 Replies
703 Views

Similar Articles

[PageSpeed] 20

Are you looking for this?

 

Request.UserHostAddress()
  

 


Jef Claes
~~~~~~~~~~

Visit my blog
0
Nemesis116
2/4/2009 5:43:43 PM

Hi,

Please try to use my code: 

public static string IPAddress
        {
            get
            {
                string userIP;
                HttpRequest Request = HttpContext.Current.Request; 

                if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != "")
                    userIP = Request.ServerVariables["REMOTE_ADDR"];
                else
                    userIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (userIP == null || userIP == "")
                    userIP = Request.UserHostAddress;
                return userIP;
            }
        }
 Let me know whether that answers your question, or if I've missed something.
Best Regards,
Bober Song
--------------------------------
Please remember to click “Mark as Answer” on the post that helps you
0
Bober
2/6/2009 6:27:40 AM

IPHostEntry host = new IPHostEntry();
host = Dns.GetHostByAddress("xxx.yyy.zzz.ccc");

string machineName = host.HostName;

In this use system.net namespace


Thanks,
Chinnu
0
chinnusamy
2/6/2009 7:01:52 AM

Hi

Try the below code

        string sHostName = Dns.GetHostName();
        IPHostEntry ipE = Dns.GetHostByName(sHostName);
        IPAddress[] IpA = ipE.AddressList;
        for (int i = 0; i < IpA.Length; i++)
        {
            Console.WriteLine("IP Address {0}: {1} ", i, IpA[i].ToString());
            lblSaved.Text = "IP Address {0}: {1}" + i.ToString() + IpA[i].ToString();
        }

 


Thanks & Regards
Prasanna T
0
prasannaprt
2/6/2009 7:08:05 AM

I have an application which gets windows username as input. Application runs in the intranet environment.

Using input username application needs to find out machine name /ip address where currently user is logged in. Bascially every user machine will be hosting WCF service to receive message from the application which gets username as input. So this application will then invoke service method for that specific username.

But how do I figure out machine name / ip address of a windows username so that I can invoke its WCF service as correct endpoint.


Blog: SEO Articles

Website: Search Engine Ranking
0
bhav27
2/10/2009 12:41:51 PM

 Hi,

So how does the user run this application?

if you are saying you need to find which machine a particular domain user is connected to using just the domain userid, i do not think that it is possible..

0
kwanann
2/10/2009 12:54:14 PM

bhav27:
I have a requirement to find out IP address/name of the machine to which a given windows user is currently logged on.
 

Is this for a web page on the intranet that the user is running or it for a winforms application on the user's PC?

If winforms please ask at:

 


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
TATWORTH
2/14/2009 2:21:44 PM

Try out this.

 Machine Name ---  System.Web.HttpContext.Current.Server.MachineName;

IP Address ---   System.Web.HttpContext.Current.Request.UserHostAddress;


Read My Blogs
0
sunilyadav165
2/14/2009 2:46:15 PM
Reply:

Similar Artilces:

How Do I get rid of \\ ( ie\\ipp//:ip address/ipp/printer) out of the start of my printer name
Hi, How Do I get rid of \\ out of the start of my printer name, I think this is stopping me printing to some printers with certain drivers(HP driver don't seem to mind). If I set printers up manual I do not have this problem and the driver works with the printer, but if I use the automated iprint way it adds \\ to the start of the printer name and it hangs my spooler file. Michael, It appears that in the past few days you have not received a response to your posting. That concerns us, and has triggered this automated reply. Has your problem been resolved? If not, you might ...

How could we get gateway's address of the machine from its IP address?
I am developing an application in asp.net using vb.net 2003? I have IP address and MAC address of a machine in my LAN. From this I want to find its default gateway address, DNS Server address if any. How could we do this in asp.net? Atleast I want to find its gateway's address. The System.Net.NetworkInformation namespace provides access to network traffic data, network address information, and notification of address changes for the local computer. The namespace also contains classes that implement the Ping utility. You can use Ping and related classes to check whether a computer ...

How to Get Machine IP Address
Hi All, Thanks for all your previous and thanks again for all future help. Kindly let me know how to get machine IP Address. Thanks and Regards, VJ http://www.rgagnon.com/howto.html Select Powerbuilder, Powerscript, scroll down to Win API/Registry <Vijay Gopal> wrote in message news:467ff09e.4684.1681692777@sybase.com... > Hi All, > > Thanks for all your previous and thanks again for all future > help. Kindly let me know how to get machine IP Address. > > Thanks and Regards, > VJ Thanks a lot.. Thanks and Regards, VJ > http://www...

How to get IP address of a machine ?
Hi Friends, Myself Ashok, working on a middle tier application in PB. I want to store IP address of my machine to some PB variable. For this I used: gethostname() window API function. 1.Declared it as global ext funtion. 2. In PB script wrote: int y,x=32 string name name=space(32) y=gethostname(name,x) messagebox(" IP address is:",name) It is giving me Blank value, Actually return value Y is coming -1, ideally it should come 0. Please help me , where I am wrong ? Thanks. Regards, Ashok Goyal SSI, New Delhi Please mail me at : agoyal@ssind.stpn.soft.n...

POST GET GET GET GET... WTH?
Hi, I'm at a loss to explain this... I have an ASPX page that I can't always navigate to. When I developed the app (it's Starter Kit Portal-based), I did it on my LAN and have had no trouble accessing the page. However, upon deployment, I see the following behavior: 1. POST request goes out looking for MyForm.aspx 2. GET request for MyForm.aspx 3. GET request for MyForm.aspx 4. ... X. GET request Sometimes, the page finally loads. Other times, it just ends up blank. Many times, it doesn't load at ALL the first POST - I just get a "The pa...

How to get Hostname, IP address, port number, DB name, instance name using Query
As we know, normally we connect to a sybase server by just identifying the node name and interfaces file and necessary properties, but currently I want to get Host-name, IP address, port number, DB name, instance name of connected server out after connection created. Does any one how to use query to do so? Does sybase provide such functionality? Seems oracle can do so... If there is no query, does sybase provides any API which can implement this? Thanks! instance name: select @@servername [assumes the DBA has defined a local entry in syservers] db name: select db_name() [can...

How I can get IP address of my machine
Hi Frinds, Myself Ashok, working on a middle tier application in PB. I want to store IP address of my machine to some PB variable. For this I used: gethostname() window API function. 1.Declared it as global ext funtion. 2. In PB script wrote: int y,x=32 string name name=space(32) y=gethostname(name,x) messagebox(" IP address is:",name) It is giving me Blank value, Actually return value Y is coming -1, ideally it should come 0. Please help me , where I am wrong ? Thanks. Regards, Ashok Goyal SSI, New Delhi Ashok, Check out Eric Aling's home pag...

Getting NIC to get a dynamic IP address from Cable Modem
Does anyone know how to get my NW 6 server to get a dynamic IP address from a cable/DSL modem? Thanks, Kevin DHCPCLNT name=board_name Add /INETCFG to the end of that to have DHCPCLNT update your INETCFG information for you. After it does that, you'll probably need to manually enable Dynamic NAT on the interface. bd NSC Volunteer SysOp ...

Get host name from IP address
does anyone have any simple C# code that can do this?pwpaust Try this.  It's a simple page that looks up both IP and name.  I've put in some data to test with, but you can enter your own text!   <%@ Page Language="C#" %> <%@ Import Namespace="System.Net" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected string DNSLookup(string domain) { string result = string.Empty; try { IPHostEntry ipHe = Dns.GetHostEntry(domain); IPAddress[] ipAd...

How to get IP address of my machine in PB ?
Hi Friends, Myself Ashok, working on a middle tier application in PB. I want to store IP address of my machine to some PB variable. For this I used: gethostname() window API function. 1.Declared it as global ext funtion. 2. In PB script wrote: int y,x=32 string name name=space(32) y=gethostname(name,x) messagebox(" IP address is:",name) It is giving me Blank value, Actually return value Y is coming -1, ideally it should come 0. Please help me , where I am wrong ? Thanks. Regards, Ashok Goyal SSI, New Delhi Please mail me at : agoyal@ssind.stpn.soft.n...

How to get IP address or name of the server?
I need to get the IP address or name of the server that runs my asp.net application. Which class, method should I use? Thanks! Try this: Request.ServerVariables["SERVER_NAME"]Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Thank you very much. I tried "SERVER_NAME", but it gives me more info than I need. I used Request.ServerVariables["HTTP_HOST"] instead. ...

How i can get IP Address of machine.
Hello All , please tell me hoe i can ge IPAddress of same machine. and IP address of machine connected in Network Do Replay. http://www.rgagnon.com/pbdetails/pb-0132.html On Thu, 27 Mar 2003 14:21:16 +0530, "Alessandro" <A.Portale@ads.it> wrote: >Hello All , > >please tell me hoe i can ge IPAddress of same machine. and IP address of >machine connected in Network > >Do Replay. > Bruce Armstrong [TeamSybase] http://www.teamsybase.com Not 1 - but 2 new books on developing with PowerBuilder http://www.pb9books.com Google Gro...

Get domain name from IP address
 Hi all,          I want to convert an Ip address to corresponding domain name if any. Do i really need to use some third party components like IP2location .. Guys Please help..   thanks in advanceplease click 'Mark as Answer' if my post helped you. http://forums.asp.net/p/1039283/1443326.aspx#1443326TUFAN01MAN HostName = System.Net.Dns.GetHostName(); IPAddres = System.Net.Dns.GetHostAddresses(HostName).GetValue(0).ToString();Thanks,AdamPlease "Mark as Answer" if this has helped you.  The above link is ...

Lookup IP Address to get domain name
Hi I have a datagrid which has a list of IP Addresses in it, I would like to resolve the IP address to show its fully qualified domain name (if found) in another column of the datagrid. Is this possible?  Is there a web service i can use, or is this functionality built into .net 2.0?Thanks in advance Check out this article:http://semichaos.com/articles/aspnet1/iptohost.aspx Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! hi,here is some information for you ,hope it helpshttp://semichaos.com/articles/aspnet1/iptohost.aspx...

Web resources about - How to get IP address/name of the machine - asp.net.getting-started

IPv4 address exhaustion - Wikipedia, the free encyclopedia
IPv4 address exhaustion is the depletion of the pool of unallocated Internet Protocol Version 4 (IPv4) addresses. The IP address space is managed ...

Falling flat: Cricket Australia to address imbalance between bat and ball after summer of tons
Cricket Australia have been left underwhelmed by the theme of flat wickets this summer from the Test portion of the season to Australia and India's ...

Lies and More Lies: Another Look at Obama's State of the Union Address
Lies and More Lies I commented on Obama's state of the union address in Brilliant Bullshit! Let's check out an alternative viewpoint. In the ...

Here's everything Facebook is doing this year to address its 'pathetic' diversity numbers
... So therefore you're less likely to be the people graduating with degrees and with the skills we need to hire. We're using TechPrep to address ...

Tom Brady Address ‘Crybaby’ Comments From Broncos Players
Tom Brady answers the question on if he is, in fact, a cry baby as Antonio Smith believes he is.

At D.C. meeting, Emanuel does little to address Laquan McDonald controversy
Chicago Tribune At D.C. meeting, Emanuel does little to address Laquan McDonald controversy Chicago Tribune Mayor Rahm Emanuel speaks at the ...

In Flint and beyond, people come together to address city's water crisis
Christian Science Monitor In Flint and beyond, people come together to address city's water crisis Christian Science Monitor As the crisis ...

Cuomo Talks $15 Minimum Wage During State Address
'Millions of low-wage workers have to choose between paying taxes and buying food'

In weekly address, Obama proposes employment insurance reforms
x YouTube Video President Obama used this week’s address to push to “modernize our employment insurance system.” If a hardworking American ...

President Obama Last State of the Union Address Recap Group Group
Trump is small potatoes. Obama had his sights set on bigger things last night.

Resources last updated: 1/22/2016 11:50:13 AM