Click to See Complete Forum and Search --> : IP Address
Jeremy Martin
Mar 7th, 2002, 09:55 AM
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
Cander
Mar 7th, 2002, 10:16 AM
this is an untested conversion of C# to VB
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
DevGrp
Mar 7th, 2002, 01:06 PM
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.
Cander
Mar 7th, 2002, 01:23 PM
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.
Nightwalker83
Mar 7th, 2002, 04:52 PM
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
Jeremy Martin
Mar 7th, 2002, 06:06 PM
I am using the new version of Visual Studio.NET
Jeremy
Jeremy Martin
Mar 7th, 2002, 07:47 PM
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
Cander
Mar 7th, 2002, 08:32 PM
tryu these changes
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
DevGrp
Mar 8th, 2002, 03:10 AM
Its really easy. Look at this C# version is below
VB.NET Version
Option Explicit On
Imports System
Imports System.Net
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ipAddr() As IPAddress = GetIpAddress()
Dim i As Int32
For i = 0 To ipAddr.Length - 1
MessageBox.Show(ipAddr(i).ToString())
Next
End Sub
Public Function GetIpAddress() As IPAddress()
Dim ipHostInfo As IPHostEntry = Dns.GetHostByName(Dns.GetHostName())
Dim ip() As IPAddress = ipHostInfo.AddressList 'returns an array of all the ip address associated with computer
Return ip 'returning the ip address
End Function
End Class
This is a fuction that returns an array of ip address
C# Version
public IPAddress[] GetIpAddress()
{
IPHostEntry ipHostInfo = Dns.GetHostByName(Dns.GetHostName());
IPAddress [] ip = ipHostInfo.AddressList;
return ip;
}
This is the calling function
IPAddress []ip = GetIpAddress();
for(int i = 0; i < ip.Length; i++)
{
netNode.Nodes.Add(ip[i].ToString());
}
Hope that helps
Cander
Mar 8th, 2002, 08:31 AM
I was close...was just in a hurry and didint put in the loop..oh and meant (0) not (1)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.