473,480 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to display my IP address?

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?
May 22 '06 #1
11 22838
Public Function Get_LocalIPAddress() As String

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

'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:eS**************@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?

May 22 '06 #2
Sam,

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

Peter

"Sam Malone" <th************@hotmail.com>
wrote:#7**************@TK2MSFTNGP02.phx.gbl...
Public Function Get_LocalIPAddress() As String

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

'return any string found

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

End Function

May 23 '06 #3
Go for it and I'd appreciate hearing which is better (if indeed one is
better than the other)
"Peter" <zl*****@sina.com> wrote in message
news:ed**************@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.GetHost Name).

Peter

"Sam Malone" <th************@hotmail.com>
wrote:#7**************@TK2MSFTNGP02.phx.gbl...
Public Function Get_LocalIPAddress() As String

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

'return any string found

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

End Function


May 23 '06 #4
cj
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.GetHost Name)

'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:eS**************@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?


May 23 '06 #5
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:
Sam,

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

Peter

"Sam Malone" <th************@hotmail.com>
wrote:#7**************@TK2MSFTNGP02.phx.gbl...
Public Function Get_LocalIPAddress() As String

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

'return any string found

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

End Function


May 23 '06 #6
Could be. It works "as is" for me in VS2005
"cj" <cj@nospam.nospam> wrote in message
news:uB**************@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.GetHost Name)

'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:eS**************@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?


May 23 '06 #7
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.

May 24 '06 #8
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
news:CD**************@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.

May 24 '06 #9
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/uti...sharptovb.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.
May 24 '06 #10
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.GetHos tByName("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:
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/uti...sharptovb.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.

May 24 '06 #11
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.

May 25 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
28306
by: Shinin | last post by:
I am trying to set up a mailto: link so that the actual address that the email is being sent to is obscured and replaced by a name. For example, I have <a href="mailto:jschmoe@abc.com">Joe...
23
3122
by: Mat | last post by:
<div id="container"> <div id="main"> <div id="header"> <p class="Address">123 Fake Street, </p> <p class="City">Crazy City, </p> <p class="Province">Ontario </p> <p class="PostalCode">H0H...
10
13416
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
19
6849
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
4
2086
by: MRBEATZ | last post by:
I'm new to this group on here, but I wanted to know if anyone knows how to display an IP address using javascript. Thanks in advance. Randy
5
3908
by: Kevin Newman | last post by:
Does anyone know of any application (AJAX or other) that will display the appropriate address for for the selected (or detected) country? If not, does anyone know where I can find a list or...
2
2184
by: HarisHohkl | last post by:
Hi, I've this function in a class to update the total value.but when i try to remove the these row highlight in Bold it crash, what should i do???? void display_total_value() { double...
4
2152
by: fiversen | last post by:
Hello, I have a site for the collegue with a football winning game. ...fussball.html there I redirect the user to an cgi-page ../f11.cgi
14
2944
by: Gordon Allott | last post by:
Hello :) The result of various incompatibilities has left me needing to somehow extract the address that a null pointer is pointing to with the null pointer being exposed to python via...
5
3658
by: alexandrus | last post by:
Hello, I have a problem. I have a email stored in database in fields (e.g. AddressLine1, Postal Code, Zip .. e.t.c.) I need a solution to display address to user in selected country format. It...
0
7044
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7045
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7087
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2985
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.