|
-
Mar 7th, 2002, 10:55 AM
#1
Thread Starter
Addicted Member
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
-
Mar 7th, 2002, 11:16 AM
#2
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
-
Mar 7th, 2002, 02:06 PM
#3
Frenzied Member
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
-
Mar 7th, 2002, 02:23 PM
#4
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.
-
Mar 7th, 2002, 05:52 PM
#5
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
-
Mar 7th, 2002, 07:06 PM
#6
Thread Starter
Addicted Member
The New Version
I am using the new version of Visual Studio.NET
Jeremy
-
Mar 7th, 2002, 08:47 PM
#7
Thread Starter
Addicted Member
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
-
Mar 7th, 2002, 09:32 PM
#8
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
-
Mar 8th, 2002, 04:10 AM
#9
Frenzied Member
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
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
-
Mar 8th, 2002, 09:31 AM
#10
I was close...was just in a hurry and didint put in the loop..oh and meant (0) not (1)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|