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
Printable View
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
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
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.
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.
Which version of vb? 6?Quote:
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
This would be correct then:
text1.text = winsock1.localip
I am using the new version of Visual Studio.NET
Jeremy
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
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
Its really easy. Look at this C# version is below
VB Code:
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
This is the calling functionCode:C# Version
public IPAddress[] GetIpAddress()
{
IPHostEntry ipHostInfo = Dns.GetHostByName(Dns.GetHostName());
IPAddress [] ip = ipHostInfo.AddressList;
return ip;
}
Code:IPAddress []ip = GetIpAddress();
for(int i = 0; i < ip.Length; i++)
{
netNode.Nodes.Add(ip[i].ToString());
}
Hope that helps
I was close...was just in a hurry and didint put in the loop..oh and meant (0) not (1)