Solved

How to get my pc's ip?

Posted on 2006-07-13
9
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 8

Assisted Solution

by:Shakti109
Shakti109 earned 50 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 200 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 200 total points
ID: 17105526
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 9

Accepted Solution

by:
jrscherer earned 100 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 150 total points
ID: 17106462
Network Interface Card
0
 
LVL 11

Assisted Solution

by:LordWabbit
LordWabbit earned 150 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

628 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