8/12/2019 Vb.net Get Local Pc Name Without Dns
I'm attempting to retrieve the client computer name from my ASP.NET web application. I'm using System.Net.Dns.GetHostName. This is returning the computer name of the web server. Jul 13, 2011 I'm attempting to retrieve the client computer name from my ASP.NET web application. I'm using System.Net.Dns.GetHostName. This is returning the computer name of.
How to get ip address in vb.net. i used below code to get local ip address but it showing dns is not declared. can any one tell me what is that Dns in the Code
VB Code
Yahia
63.6k77 gold badges9393 silver badges124124 bronze badges
Rajkumar ReddyRajkumar Reddy
1,12955 gold badges1616 silver badges2828 bronze badges
7 Answers
Since I get the feeling that, the question (in the title) is not fully answered yet ...
... obviously this is not exactly what the OP asked for, but just from the title and google links, this should answer what people coming here are looking for.
Btw LevitLevit
GetHostByName() seems to be deprecated, GetHostEntry() like this works the same way, without throwing a warning.
12.4k77 gold badges3939 silver badges4242 bronze badges
Dns is a class in the namespace System.Net which provides functionality regarding the 'Domain Name System' (thus the name Dns ) - see http://msdn.microsoft.com/en-us/library/system.net.dns.gethostname.aspx
63.6k77 gold badges9393 silver badges124124 bronze badges
AlphaMaleAlphaMale
21k22 gold badges4949 silver badges7474 bronze badges
bibi
2,65744 gold badges1818 silver badges3939 bronze badges
DeepeshDeepesh
ips = Dns.GetHostAddresses(hostname)
here is a sample codeMSDN
bitsmonkeybitsmonkey
You can get local ip address of system using below code:
Dr. Rajesh RolenDr. Rajesh Rolen
7,9083232 gold badges9393 silver badges168168 bronze badges
This will most likely give IPv6 address
And
This will give IPv4 address
![]()
My VB is rusty so here is a C# code that works for me.
I hope this helps.
JasonMArcher
9,7311010 gold badges4949 silver badges4949 bronze badges
abhiabhi
Not the answer you're looking for? Browse other questions tagged vb.net or ask your own question.
How can you get the FQDN of a local machine in C#?
Sam
23.8k2020 gold badges125125 silver badges165165 bronze badges
Gabe
10 Answers
NOTE: This solution only works when targeting the .NET 2.0 (and newer) frameworks.
UPDATE
Since a lot of people have commented that Sam's Answer is more concise I've decided to add some comments to the answer.
The most important thing to note is that the code I gave is not equivalent to the following code:
While in the general case when the machine is networked and part of a domain, both methods will generally produce the same result, in other scenarios the results will differ.
A scenario where the output will be different is when the machine is not part of a domain. In this case, the
Dns.GetHostEntry('LocalHost').HostName will return localhost while the GetFQDN() method above will return the NETBIOS name of the host.
This distinction is important when the purpose of finding the machine FQDN is to log information, or generate a report. Most of the time I've used this method in logs or reports that are subsequently used to map information back to a specific machine. If the machines are not networked, the
localhost identifier is useless, whereas the name gives the needed information.
So ultimately it's up to each user which method is better suited for their application, depending on what result they need. But to say that this answer is wrong for not being concise enough is superficial at best.
See an example where the output will be different: http://ideone.com/q4S4I0
Community♦
Mike DinescuMike Dinescu
40.2k88 gold badges8686 silver badges127127 bronze badges
Matt ZMatt Z
98811 gold badge77 silver badges1212 bronze badges
This is covered by this article. This technique is more brief than the accepted answer and probably more reliable than the next most-voted answer. Note that as far as I understand, this doesn't use NetBIOS names, so it should be suitable for Internet use.
.NET 2.0+.NET 1.0 - 1.1SamSam
23.8k2020 gold badges125125 silver badges165165 bronze badges
halr9000halr9000
6,97444 gold badges2828 silver badges3434 bronze badges
And for Framework 1.1 is as simple as this:
And then remove the machine NETBIOS name to retrieve only the domainName
javizcainojavizcaino
You can try the following:
This shoud give you the FQDN of the current local machine (or you can specify any host).
Kiquenet
7,2992828 gold badges111111 silver badges204204 bronze badges
UT-Fan-05UT-Fan-05
A slight improvement on Matt Z's answer so that a trailing full stop isn't returned if the computer is not a member of a domain:
BoscoBosco
Used this as one of my options to combine host name and domain name for building a report, added the generic text to fill in when domain name was not captured, this was one of the customers requirements.
I tested this using C# 5.0, .Net 4.5.1
Built using ideas from Miky Dinescu solution.
user3500031user3500031
We have implemented suggested result to use this way:
However, turned out that this does not work right when computer name is longer than 15 characters and using NetBios name. The Environment.MachineName returns only partial name and resolving host name returns same computer name.
After some research we found a solution to fix this problem:
This resolved all problems including computer name.
btomasbtomas
If you want to tidy it up, and handle exceptions, try this:
Roger WillcocksRoger Willcocks
protected by Mike DinescuNov 19 '14 at 18:41
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead? Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |