Go Premium for a chance to win a PS4. Enter to Win


How to get my pc's ip?

Posted on 2006-07-13
Medium Priority
Last Modified: 2008-02-01
I am using ADSL connection, the ip may change, my program need to check for fixed time interval of the pc's ip.
Is there any sample code?

Then I need to write it to a log file and write to DB.

Question by:turbot_yu
  • 3
  • 2
  • 2
  • +2

Assisted Solution

Shakti109 earned 200 total points
ID: 17105366

Which version of O/S will the application run on?

If it is pre-XP, then the function to determine I.P will be a little more involved.
If it is XP and above a VERY simpe call to a native method will do it.

Also, which version of studio will you be developing in? 2003 or 2005?

Answer these two questions and we can find the right path for you to take.

Assisted Solution

nickhoggard earned 800 total points
ID: 17105512

Check out the System.Net.DNS class.  The following article covers getting the IP address from it:



Assisted Solution

nickhoggard earned 800 total points
ID: 17105526
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

jrscherer earned 400 total points
ID: 17105828
Your question is a little bit tricky, since you may have several NICs installed and active in your computer. Each NIC may have several IP addresses allocated to it.

Here is a function to get all IP addresses in your system of all enabled NICs. May be this can help you to find your solution
You will need to have a Reference to System.Management and import it.

    Private Function GetAllActiveIPs() As String
        Dim al As New ArrayList
            Dim mc As ManagementClass
            Dim mo As ManagementObject
            mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
            Dim moc As ManagementObjectCollection = mc.GetInstances()

            For Each mo In moc
                If CBool(mo.Item("IPEnabled")) Then

                    Dim str() As String = CType(mo.Item("IPAddress"), String())

                    For Each strx As String In str

                End If
        Catch ex As Exception
            Return ex.ToString
        End Try

        Dim strg As String = String.Empty
        For Each strgx As String In al
            strg &= strgx & vbCrLf

        Return strg
    End Function

Place a button and a label onto your form and

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = GetAllActiveIPs()
    End Sub



Author Comment

ID: 17106009
The OS is xp. The version is 2003.

What is the full name of NIC? Thanks.
LVL 11

Assisted Solution

LordWabbit earned 600 total points
ID: 17106462
Network Interface Card
LVL 11

Assisted Solution

LordWabbit earned 600 total points
ID: 17106473
Oh yeah forgot to mention if you are running a bluetooth device it will also have a IP address, also if you have vmware installed it adds two virtual nics as well so it's not always straight forward to programatically determine the PC's ip address (not sure what microsofts vitual pc does, installed it once didn't like it much)

Author Comment

ID: 17117364
There is no bluetooth, what is vmware, thanks.
LVL 11

Expert Comment

ID: 17120028
vmware is a virtual pc emulator, chances are if you don't know what it is, it's not installed either so no worries.  Using vmware you can create another virtual pc which runs on your current os, whats the point you ask, well if you are deploying into a win2k3 environment you can set up one in a virtual pc to test the deployment process / docs etc.  Also we had a case where some of a clients customers where still running win98 (sad but true) and our software had to work on that, so we set up a virtual pc running windows 98 to test if we were using functions / methods which would not work in that OS.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question