|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to display my IP address?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? 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? 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 > 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 >> > > 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 >> > > 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. 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. > 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. 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. > > 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. 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? > > 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? >>
Access DB Issues - Again
Calling API functions dynamically? arrghh dot vs comma Thread takes up 100% CPU Caret Hiding SortCompare of DataGridView - how to? Want to Eary Bind Instead of Late Bind Object an IE Object Regular Expression Excluding Exact String Query based of a value in a combo box Translation to vb from C# ? |
|||||||||||||||||||||||