Results 1 to 10 of 10

Thread: IP Address

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207

    IP Address

    Does anyone know how to get the ip address of your computer, from a nic card, using the new version of visual studio.

    Any help would be appreciated
    Jeremy

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    this is an untested conversion of C# to VB

    Code:
    Imports System
    Imports System.Net
    
    Dim strHostName As String= Dns.GetHostName 
    Dim ipEntry As IPHostEntry = Dns.GetHostByName (strHostName)
    Dim IpAddr As IPAddress = ipEntry.AddressList
    Dim myIP As String
    
    myIp = IpAddr.ToString
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    That seems to be right Cander, except that IpAddr should be an array since ipEntry.Addresslist returns an array.

    It returns all ip address associated with the computer.

    I'm trying to figure how to detect the kind of connection of the computer and also the speed.
    Dont gain the world and lose your soul

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    ahh I see so in C#

    the [] is an array declaration vs. VB's ()..ok I got it..that confused me for when I was transferring over the C# code.
    Im trying to learn the C# syntax for translation purposes between
    it and VB for tims when I may need code to do something in VB, but can only find C# code....like in this situation.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: IP Address

    Originally posted by Jeremy Martin
    Does anyone know how to get the ip address of your computer, from a nic card, using the new version of visual studio.

    Any help would be appreciated
    Jeremy
    Which version of vb? 6?

    This would be correct then:

    text1.text = winsock1.localip
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207

    The New Version

    I am using the new version of Visual Studio.NET

    Jeremy

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207

    Error

    When I tried to code from Cander I get this error message:

    Value of type '1-dimensional array of System.Net.IPAddress' cannot be converted to 'System.Net.IPAddress'.

    Jeremy

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    tryu these changes

    Code:
    Imports System
    Imports System.Net
    
    Dim strHostName As String= Dns.GetHostName 
    Dim ipEntry As IPHostEntry = Dns.GetHostByName (strHostName)
    Dim IpAddr() As IPAddress = ipEntry.AddressList
    Dim myIP As String
    
    myIp = IpAddr(1).ToString
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Its really easy. Look at this C# version is below

    VB Code:
    1. VB.NET Version
    2.  
    3. Option Explicit On
    4. Imports System
    5. Imports System.Net
    6.  
    7. Public Class Form1
    8.     Inherits System.Windows.Forms.Form
    9.  
    10.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    11.         Dim ipAddr() As IPAddress = GetIpAddress()
    12.         Dim i As Int32
    13.  
    14.         For i = 0 To ipAddr.Length - 1
    15.             MessageBox.Show(ipAddr(i).ToString())
    16.         Next
    17.  
    18.     End Sub
    19.  
    20.     Public Function GetIpAddress() As IPAddress()
    21.         Dim ipHostInfo As IPHostEntry = Dns.GetHostByName(Dns.GetHostName())
    22.  
    23.         Dim ip() As IPAddress = ipHostInfo.AddressList  'returns an array of all the ip address associated with computer
    24.  
    25.         Return ip 'returning the ip address
    26.  
    27.     End Function
    28. End Class

    This is a fuction that returns an array of ip address

    Code:
     C# Version
    
    public IPAddress[] GetIpAddress()
    {
    	IPHostEntry ipHostInfo =  Dns.GetHostByName(Dns.GetHostName());
    			
    	IPAddress [] ip = ipHostInfo.AddressList;
    
    	return ip;
    					
    }
    This is the calling function

    Code:
    IPAddress []ip = GetIpAddress();
    
    for(int i = 0; i < ip.Length; i++)
    {
          netNode.Nodes.Add(ip[i].ToString());		
    }

    Hope that helps
    Last edited by DevGrp; Mar 8th, 2002 at 04:33 AM.
    Dont gain the world and lose your soul

  10. #10
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    I was close...was just in a hurry and didint put in the loop..oh and meant (0) not (1)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width