473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 22834
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
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.