Home All Groups Group Topic Archive Search About

how to display my IP address?

Author
22 May 2006 8:53 PM
cj
I can get my DNS Name, Machine Name and User Name like

MessageBox.Show("NetBIOS Name:  " & System.Environment.MachineName &
vbCrLf & _
"DNS Name:      " & System.Net.Dns.GetHostByName("LocalHost").HostName &
vbCrLf & _
"User Name:     " & System.Environment.UserName)

how can I display my IP address?

Also, what is the difference between a DNS Name and a NetBIOS name?

Author
22 May 2006 9:38 PM
Sam Malone
Public Function Get_LocalIPAddress() As String

Dim h As System.Net.IPHostEntry =
System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)

'return any string found

Get_LocalIPAddress = CType(h.AddressList.GetValue(0),
System.Net.IPAddress).ToString

End Function


Show quoteHide quote
"cj" <cj@nospam.nospam> wrote in message
news:eSlCGHefGHA.4172@TK2MSFTNGP04.phx.gbl...
>I can get my DNS Name, Machine Name and User Name like
>
> MessageBox.Show("NetBIOS Name:  " & System.Environment.MachineName &
> vbCrLf & _
> "DNS Name:      " & System.Net.Dns.GetHostByName("LocalHost").HostName &
> vbCrLf & _
> "User Name:     " & System.Environment.UserName)
>
> how can I display my IP address?
>
> Also, what is the difference between a DNS Name and a NetBIOS name?
Author
23 May 2006 12:36 AM
Peter
Sam,

Maybe we should use System.Net.Dns.Resolve(System.Net.Dns.GetHostName)
instead of
System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).

Peter

"Sam Malone" <the_sam_mal***@hotmail.com>
wrote:#7r6ZgefGHA.5***@TK2MSFTNGP02.phx.gbl...
Show quoteHide quote
> Public Function Get_LocalIPAddress() As String
>
> Dim h As System.Net.IPHostEntry =
> System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
>
> 'return any string found
>
> Get_LocalIPAddress = CType(h.AddressList.GetValue(0),
> System.Net.IPAddress).ToString
>
> End Function
>
Author
23 May 2006 2:58 AM
Sam Malone
Go for it and I'd appreciate hearing which is better (if indeed one is
better than the other)


Show quoteHide quote
"Peter" <zlxm***@sina.com> wrote in message
news:ednhxCgfGHA.1320@TK2MSFTNGP04.phx.gbl...
> Sam,
>
> Maybe we should use System.Net.Dns.Resolve(System.Net.Dns.GetHostName)
> instead of
> System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).
>
> Peter
>
> "Sam Malone" <the_sam_mal***@hotmail.com>
> wrote:#7r6ZgefGHA.5***@TK2MSFTNGP02.phx.gbl...
>> Public Function Get_LocalIPAddress() As String
>>
>> Dim h As System.Net.IPHostEntry =
>> System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
>>
>> 'return any string found
>>
>> Get_LocalIPAddress = CType(h.AddressList.GetValue(0),
>> System.Net.IPAddress).ToString
>>
>> End Function
>>
>
>
Author
23 May 2006 12:50 PM
cj
I don't get an IP address.  That gives me:

? System.Net.Dns.Resolve(System.Net.Dns.GetHostName)
{System.Net.IPHostEntry}
     AddressList: {Length=1}
     Aliases: {Length=0}
     HostName: "CJ"

I'm using VS2003 if that changes things.  I should have mentioned it.

Peter wrote:
Show quoteHide quote
> Sam,
>
> Maybe we should use System.Net.Dns.Resolve(System.Net.Dns.GetHostName)
> instead of
> System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).
>
> Peter
>
> "Sam Malone" <the_sam_mal***@hotmail.com>
> wrote:#7r6ZgefGHA.5***@TK2MSFTNGP02.phx.gbl...
>> Public Function Get_LocalIPAddress() As String
>>
>> Dim h As System.Net.IPHostEntry =
>> System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
>>
>> 'return any string found
>>
>> Get_LocalIPAddress = CType(h.AddressList.GetValue(0),
>> System.Net.IPAddress).ToString
>>
>> End Function
>>
>
>
Author
24 May 2006 6:32 AM
Jeffrey Tan[MSFT]
Hi cj,

Thanks for your feedback!

You can get the IP address like this:
private void button1_Click(object sender, System.EventArgs e)
{
    IPHostEntry hostInfo = Dns.GetHostByName("host name");
    byte[] ipaddr=hostInfo.AddressList[0].GetAddressBytes();
    MessageBox.Show("IP Address:
"+ipaddr[0]+"."+ipaddr[1]+"."+ipaddr[2]+"."+ipaddr[3]+"\n");
}

This code snippet works well on my side. Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
24 May 2006 8:38 AM
Cor Ligthert [MVP]
Jeffrey,

I had to smile, but it is true, be aware that this is a VB Net newsgroup and
that your code can look confusing for some people searching this newsgroup.

Cor

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> schreef in bericht
Show quoteHide quote
news:CDJVevvfGHA.2260@TK2MSFTNGXA01.phx.gbl...
> Hi cj,
>
> Thanks for your feedback!
>
> You can get the IP address like this:
> private void button1_Click(object sender, System.EventArgs e)
> {
> IPHostEntry hostInfo = Dns.GetHostByName("host name");
> byte[] ipaddr=hostInfo.AddressList[0].GetAddressBytes();
> MessageBox.Show("IP Address:
> "+ipaddr[0]+"."+ipaddr[1]+"."+ipaddr[2]+"."+ipaddr[3]+"\n");
> }
>
> This code snippet works well on my side. Hope this helps!
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Community Support
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
Author
24 May 2006 11:21 AM
Jeffrey Tan[MSFT]
Oh, yes, it seems that I mislooked the queue name :-(

Anyway, a C# to VB.net converter can help here:
http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
24 May 2006 12:35 PM
cj
The converter doesn't work exactly but close enough.  Because I want to
know the ip address of the machine this is running on and don't want to
have to hard code the computers name in the code I changed the dim
hostinfo line as shown below.  Thanks for the code.

Dim hostInfo As System.Net.IPHostEntry = _
System.Net.Dns.GetHostByName(System.Net.Dns.GetHostByName("LocalHost").HostName)

Dim ipaddr As Byte() = hostInfo.AddressList(0).GetAddressBytes

MessageBox.Show("IP Address:" & ipaddr(0) & "." & ipaddr(1) & "." & _
ipaddr(2) & "." & ipaddr(3) & "" & Microsoft.VisualBasic.Chr(10) & "")


Jeffrey Tan[MSFT] wrote:
Show quoteHide quote
> Oh, yes, it seems that I mislooked the queue name :-(
>
> Anyway, a C# to VB.net converter can help here:
> http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Community Support
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
Author
25 May 2006 1:35 AM
Jeffrey Tan[MSFT]
Hi cj,

I am glad you have figured out what you need. If you need further help,
please feel free to post. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
23 May 2006 12:47 PM
cj
GetHostEntry is not a member of System.Net.Dns

Perhaps it's because I'm using VS2003?

Sam Malone wrote:
Show quoteHide quote
> Public Function Get_LocalIPAddress() As String
>
> Dim h As System.Net.IPHostEntry =
> System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
>
> 'return any string found
>
> Get_LocalIPAddress = CType(h.AddressList.GetValue(0),
> System.Net.IPAddress).ToString
>
> End Function
>
>
> "cj" <cj@nospam.nospam> wrote in message
> news:eSlCGHefGHA.4172@TK2MSFTNGP04.phx.gbl...
>> I can get my DNS Name, Machine Name and User Name like
>>
>> MessageBox.Show("NetBIOS Name:  " & System.Environment.MachineName &
>> vbCrLf & _
>> "DNS Name:      " & System.Net.Dns.GetHostByName("LocalHost").HostName &
>> vbCrLf & _
>> "User Name:     " & System.Environment.UserName)
>>
>> how can I display my IP address?
>>
>> Also, what is the difference between a DNS Name and a NetBIOS name?
>
>
Author
23 May 2006 8:34 PM
Sam Malone
Could be. It works "as is" for me in VS2005


Show quoteHide quote
"cj" <cj@nospam.nospam> wrote in message
news:uBajecmfGHA.2456@TK2MSFTNGP04.phx.gbl...
> GetHostEntry is not a member of System.Net.Dns
>
> Perhaps it's because I'm using VS2003?
>
> Sam Malone wrote:
>> Public Function Get_LocalIPAddress() As String
>>
>> Dim h As System.Net.IPHostEntry =
>> System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
>>
>> 'return any string found
>>
>> Get_LocalIPAddress = CType(h.AddressList.GetValue(0),
>> System.Net.IPAddress).ToString
>>
>> End Function
>>
>>
>> "cj" <cj@nospam.nospam> wrote in message
>> news:eSlCGHefGHA.4172@TK2MSFTNGP04.phx.gbl...
>>> I can get my DNS Name, Machine Name and User Name like
>>>
>>> MessageBox.Show("NetBIOS Name:  " & System.Environment.MachineName &
>>> vbCrLf & _
>>> "DNS Name:      " & System.Net.Dns.GetHostByName("LocalHost").HostName &
>>> vbCrLf & _
>>> "User Name:     " & System.Environment.UserName)
>>>
>>> how can I display my IP address?
>>>
>>> Also, what is the difference between a DNS Name and a NetBIOS name?
>>