HOw to get system IP in VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravipanand
    New Member
    • Sep 2008
    • 4

    HOw to get system IP in VB6

    Hi,

    Please tell me the code for getting IP address of a current system in VB6.

    Thanx
    Ravi Prakash
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    i'm not sure about VB6 but if you can connecting to WMI would probably be the easiest way although you can read it from the registry also .

    I can work out and post some vb .net or VB script code for either of these methods later if you want to try it, just let me know .

    sorry, I use .net but probably need to get VB6 as would make it easier to answer these questions!

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      I might be interested in seeing some basic WMI code here if you can.

      I did some a while back in my domain setup at work, but don't have any to hand. It would be good just to have a starter posted. Readers can always build on from there.

      Comment

      • jg007
        Contributor
        • Mar 2008
        • 283

        #4
        lol , this code is pretty awfull and probably would be better with a treeview !

        at the moment all it does is output all network adaptor names , descriptions and ip addresses to a list box

        one thing I had forgotten is that you can have more than one ip address if you have multiple cards etc so I am not sure how work round that one

        you will also need to add the ' systems.managme nt ' reference to your project so I haven't a clue if it will work okay with VB 6 or will need to be ammended

        Code:
        Imports System
        Imports System.Management
        Public Class Form1
        
            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
                Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_NetworkAdapterConfiguration")
        
                Dim ListNetCards As ManagementObjectCollection
        
        
                Dim ipadds As Array
        
        
                ListNetCards = searcher.Get()
        
                For Each Netcard In ListNetCards
        
        
                    For Each prop In Netcard.Properties
        
                        If Not prop.Value Is Nothing Then
        
                            Select Case UCase(prop.Name)
        
                                Case "IPADDRESS"
        
                                    ipadds = prop.Value
                                    For Each ipadd In ipadds
                                        ListBox1.Items.Add("IP Address : " & ipadd.ToString)
                                    Next
        
                                Case "DESCRIPTION"
                                    ListBox1.Items.Add("Description : " & prop.Value.ToString)
        
                                Case "DHCPENABLED"
                                    ListBox1.Items.Add("DHCP Enabled : " & prop.Value.ToString)
                                Case "CAPTION"
                                    ListBox1.Items.Add("Caption : " & prop.Value.ToString)
        
                            End Select
        
                        End If
        
        
                    Next
        
        
        
                    ListBox1.Items.Add("")
                    ListBox1.Items.Add("*******")
                    ListBox1.Items.Add("")
        
                Next
        
            End Sub
        End Class

        Comment

        • jg007
          Contributor
          • Mar 2008
          • 283

          #5
          looking at the output from my machine I only have one with DHCP enabled so that shows mine but if somebody has wireless and ethernet that will not work as they will probably have DHCP enabled for both

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            Thanks. It's not the functionality, but the individual building blocks of code that are interesting :)

            Comment

            • Ali Rizwan
              Banned
              Contributor
              • Aug 2007
              • 931

              #7
              Add winsock control.
              and use following code to get system IP address.

              Code:
              msgbox winsock1.LocalIP
              Regards
              ** Link Removed **
              >> ALI <<

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #8
                Ali, thank you for your contribution, but please remember how close you are to a permanent ban from the site.

                Your web site is NOT allowed in a signature in a technical forum.

                I suggest you have a good read of the site rules before posting again (You can link there from any page on the site). Technically, you could have been banned permanently for this last post. If you want to remain an active member I suggest you make very sure you don't break any more rules ever.

                Comment

                • Ali Rizwan
                  Banned
                  Contributor
                  • Aug 2007
                  • 931

                  #9
                  Thankyou for reminding me.
                  I ll be carefull next time.

                  >> ALI <<

                  Comment

                  Working...