Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to get my pc's ip?

Posted on 2006-07-13
9
Medium Priority
?
281 Views
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.

Thx
0
Comment
Question by:turbot_yu
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 8

Assisted Solution

by:Shakti109
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.
0
 
LVL 5

Assisted Solution

by:nickhoggard
nickhoggard earned 800 total points
ID: 17105512
Hi,

Check out the System.Net.DNS class.  The following article covers getting the IP address from it:
http://www.codeproject.com/csharp/network.asp

Cheers

Nick
0
 
LVL 5

Assisted Solution

by:nickhoggard
nickhoggard earned 800 total points
ID: 17105526
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Accepted Solution

by:
jrscherer earned 400 total points
ID: 17105828
Hi,
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
        Try
            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
                        al.Add(strx)
                    Next

                End If
            Next
        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
        Next

        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

Jack.net

0
 

Author Comment

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

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

Assisted Solution

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

Assisted Solution

by:LordWabbit
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)
0
 

Author Comment

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

Expert Comment

by:LordWabbit
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.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

580 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