Click here to Skip to main content
11,437,713 members (32,139 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
Hello Guys,

How can I get the ip of my PC?

Regards

Haluk
Posted 16-Dec-12 23:45pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

1st.
using System.Net;
2nd. Dns.GetHostAddresses(Dns.GetHostName()) - it returns array of IPAddress
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Go through this article. It has the sample as well.
http://stackoverflow.com/questions/1069103/how-to-get-my-own-ip-address-in-c[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Using command prompt:
ipconfig

Using C++ code:
/**
 * This function retrieves the list of available IP on this computer.
 * Usefull only for computer with several network cards
 * note that 127.0.0.1 is not listed.
 */
list<string> GetIpList()
{
    list<string> ret;
    char name[1024];
    hostent *ips;
    /* get name of computer */
    if(0 == gethostname(name, sizeof name)) {
        /* retreive IP addresses*/
        ips = gethostbyname(name);
        if(NULL != ips) {
            int i;
            for (i = 0; ips->h_addr_list[i] != 0; ++i) {
                 in_addr addr;
                memcpy(&addr, ips->h_addr_list[i], sizeof(struct in_addr));
                ret.push_back(inet_ntoa(addr));
            }
        }
    }
    return ret;
}

using C# code:
System.Net.IPAddress[] addresses = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
// optional: create a list of string to display addresses in the usual ways
// ipv4 : 192.168.1.1 or ipv6 : fd50:5829:2f2c:7ab:ef78%20
List<string> ips = new List<string>();
foreach (System.Net.IPAddress addr in addresses)
{
   ips.Add(addr.ToString());
}
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Do you have C# code? Because I am using VS2010
  Permalink  
Comments
jibesh at 18-Dec-12 4:33am
   
http://www.codeproject.com/Answers/307645/Find-IP-Address-Machine-Name.aspx#answer2

check this link. its already been asked and answered. Its kid request that better do a search in code project to match your question, if not found you are welcome to add your question.
Abhishek Pant at 18-Dec-12 6:03am
   
just use comment widget if you do not have solution.

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



Advertise | Privacy | Mobile
Web03 | 2.8.150506.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100