Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys,

How can I get the ip of my PC?

Regards

Haluk
Posted

1st.
C#
using System.Net;

2nd. Dns.GetHostAddresses(Dns.GetHostName()) - it returns array of IPAddress
 
Share this answer
 
Go through this article. It has the sample as well.
http://stackoverflow.com/questions/1069103/how-to-get-my-own-ip-address-in-c[^]
 
Share this answer
 
Using command prompt:
ipconfig


Using C++ code:
C++
/**
 * 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:
C#
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());
}
 
Share this answer
 
v3
Do you have C# code? Because I am using VS2010
 
Share this answer
 
Comments
Jibesh 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900