Click here to Skip to main content
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 22:45pm
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.
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  

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.140709.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid