How can I read the client's machine/computer name from the browser?
Is it possible using JavaScript and/or ASP.NET?
-
I am not sure but probably it's not allowed by JS security policy – Dasha Salo May 28 '09 at 18:37
-
7Well, you could add an input field and ask the user to type in his computer name ;-) – Andre Miller May 28 '09 at 18:51
-
12the reason is for a IT support system where the client wants to be able to attach the computer/machine name to a ticket submitted by a the user – MetaGuru May 28 '09 at 18:54
-
1Ryan, that was pretty much the exact reason the internal app I had made needed it as well. The app had to attach the computer name to service request tickets generated from a specific machine. The user didn't have to know what the computer name was when filling out the ticket. – Kelsey May 28 '09 at 22:33
11 Answers
You can do it with IE 'sometimes' as I have done this for an internal application on an intranet which is IE only. Try the following:
function GetComputerName() {
try {
var network = new ActiveXObject('WScript.Network');
// Show a pop up if it works
alert(network.computerName);
}
catch (e) { }
}
It may or may not require some specific security setting setup in IE as well to allow the browser to access the ActiveX object.
Here is a link to some more info on WScript: More Information

- 45,213
- 22
- 199
- 169

- 47,246
- 16
- 124
- 162
Browser, Operating System, Screen Colors, Screen Resolution, Flash version, and Java Support should all be detectable from JavaScript (and maybe a few more). However, computer name is not possible.
EDIT: Not possible across all browser at least.

- 7,692
- 4
- 32
- 47
Well you could get the ip address using asp.net, then do a reverse DNS lookup on the ip to get the hostname.
From the ASP.NET Developer's cookbook ... Performing a Reverse-DNS Lookup.

- 475
- 6
- 24

- 16,772
- 9
- 42
- 55
-
I ran that code with 192.168.1.100 (ip address of machine hosting browser) and it gave an error: 'Error:The requested name is valid, but no data of the requested type was found' – MetaGuru May 28 '09 at 22:49
-
5192.168.*.* is a private ip address, you'll need to run the code on a computer on the private network and have a DNS server on the network for this to work. – Mark May 29 '09 at 00:31
-
1This is not possible is some cases, as the webserver might be behind an advanced proxy/firewall. Then all you will ever get is the IP-adress/hostname of this proxy/firewall. This is typically for big webfarms. So be sure to check the final production network topology before implementing this. – JDC Apr 01 '15 at 10:02
-
2provided url is down, this is why url-only answers are frowned upon. can the link be updated? Can someone inject the relevant bits of code and provide a citation reference instead? – Shaun Wilson Dec 09 '16 at 18:56
-
2
It is not possible to get the users computer name with Javascript. You can get all details about the browser and network. But not more than that.
Like some one answered in one of the previous question today.
I already did a favor of visiting your website, May be I will return or refer other friends.. I also told you where I am and what OS, Browser and screen resolution I use Why do you want to know the color of my underwear? ;-)
You cannot do it using asp.net as well.

- 22,920
- 8
- 63
- 107
-
16Eh, if you're building an internal application in an enterprise setting, you'd be surprised at how helpful knowing this information would be. We track errors in our app, and the IP addresses the user use change depending on their environment (wifi, LAN, VPN). Being able to get their computer name from logs sent to the server from the client, and using enterprise tools to view installed software and windows patches on that machine is then possible. Without direct access to the computer. Helps a lot in troubleshooting without having to get the non-technical employee involved. – Johnathon Sullinger Apr 06 '17 at 19:43
-
@JohnathonSullinger For internal applications you can run a simple localhost webserver (that runs in the background as a Windows Service) that returns information about the user's computer which can be queried by web-applications by making AJAX/`fetch` requests - obviously make sure it's secured and only returns minimal, non-secret data, but it's one way to allow web-applications to integrate with the user's desktop computer. This is how how things like Dell's Service-Tag finder work (assuming you have the Dell Support Assistant installed). – Dai Dec 02 '20 at 00:16
-
@Dai Running a webserver on 7,000+ client desktops in our enterprise is not something we want. You have to patch and maintain that webserver and then deal with different types of devices like Chromebooks, Macbooks, Windows ARM and x86 devices etc. Sorting through and managing all of that would be a nightmare. – Johnathon Sullinger Dec 02 '20 at 03:37
-
What we're doing is pulling the IP from the machine and logging that server side from the HTTP request. IP addresses tend to change out from under us but that only happens once every few weeks or months per device. For support, this is typically not an issue. For sensitive audit related things we just do a DNS lookup for the IP in our AD domain controllers as part of the server side processing of the logs. We then write the log entry. This works sincesince all our devices have DNS in front of them that matches the machine name. – Johnathon Sullinger Dec 02 '20 at 03:41
Try getting the client computer name in Mozilla Firefox by using the code given below.
netscape.security.PrivilegeManager.enablePrivilege( 'UniversalXPConnect' );
var dnsComp = Components.classes["@mozilla.org/network/dns-service;1"];
var dnsSvc = dnsComp.getService(Components.interfaces.nsIDNSService);
var compName = dnsSvc.myHostName;
Also, the same piece of code can be put as an extension, and it can called from your web page.
Please find the sample code below.
Extension code:
var myExtension = {
myListener: function(evt) {
//netscape.security.PrivilegeManager.enablePrivilege( 'UniversalXPConnect' );
var dnsComp = Components.classes["@mozilla.org/network/dns-service;1"];
var dnsSvc = dnsComp.getService(Components.interfaces.nsIDNSService);
var compName = dnsSvc.myHostName;
content.document.getElementById("compname").value = compName ;
}
}
document.addEventListener("MyExtensionEvent", function(e) { myExtension.myListener(e); }, false, true); //this event will raised from the webpage
Webpage Code:
<html>
<body onload = "load()">
<script>
function showcomp()
{
alert("your computer name is " + document.getElementById("compname").value);
}
function load()
{
//var element = document.createElement("MyExtensionDataElement");
//element.setAttribute("attribute1", "foobar");
//element.setAttribute("attribute2", "hello world");
//document.documentElement.appendChild(element);
var evt = document.createEvent("Events");
evt.initEvent("MyExtensionEvent", true, false);
//element.dispatchEvent(evt);
document.getElementById("compname").dispatchEvent(evt); //this raises the MyExtensionEvent event , which assigns the client computer name to the hidden variable.
}
</script>
<form name="login_form" id="login_form">
<input type = "text" name = "txtname" id = "txtnamee" tabindex = "1"/>
<input type="hidden" name="compname" value="" id = "compname" />
<input type = "button" onclick = "showcomp()" tabindex = "2"/>
</form>
</body>
</html>

- 9,053
- 5
- 35
- 54

- 37
- 2
-
1NB: This code is very old and will not work in any current version of Firefox -- not even in extensions. – Sep 20 '18 at 02:09
There is no way to do so, as JavaScript does not have an access to computer name, file system and other local info. Security is the main purpose.
-
5"This is a part of JavaScript specification" — It isn't. Those are things which are very much *not* part of the language specification. When they are available, it is through functions provided by the host environment. Browsers don't provide them. NodeJS does. (To take two common examples). – Quentin Sep 27 '16 at 12:12
-
Thanks @Quentin, good correction. It's browser limitation, by security reason. – Denys Sep 28 '16 at 16:21
No this data is not exposed. The only data that is available is what is exposed through the HTTP request which might include their OS and other such information. But certainly not machine name.

- 31,265
- 19
- 98
- 114
<html>
<body onload = "load()">
<script>
function load(){
try {
var ax = new ActiveXObject("WScript.Network");
alert('User: ' + ax.UserName );
alert('Computer: ' + ax.ComputerName);
}
catch (e) {
document.write('Permission to access computer name is denied' + '<br />');
}
}
</script>
</body>
</html>

- 3,648
- 1
- 14
- 22

- 331
- 4
- 5
There is some infos to parse into the webRTC header.
var p = new window.RTCPeerConnection();
p.createDataChannel(null);
p.createOffer().then((d) => p.setLocalDescription(d))
p.onicecandidate = (e) => console.log(p.localDescription)

- 11,480
- 1
- 88
- 87
-
Doesn't this just always say `127.0.0.1`? Or maybe I don't understand your answer and it might be worth elaborating a bit more! :) – cutsoy Nov 28 '22 at 21:38
An updated version from Kelsey :
$(function GetInfo() {
var network = new ActiveXObject('WScript.Network');
alert('User ID : ' + network.UserName + '\nComputer Name : ' + network.ComputerName + '\nDomain Name : ' + network.UserDomain);
document.getElementById('<%= currUserID.ClientID %>').value = network.UserName;
document.getElementById('<%= currMachineName.ClientID %>').value = network.ComputerName;
document.getElementById('<%= currMachineDOmain.ClientID %>').value = network.UserDomain;
});
To store the value, add these control :
<asp:HiddenField ID="currUserID" runat="server" /> <asp:HiddenField ID="currMachineName" runat="server" /> <asp:HiddenField ID="currMachineDOmain" runat="server" />
Where you also can calling it from behind like this :
Page.ClientScript.RegisterStartupScript(this.GetType(), "MachineInfo", "GetInfo();", true);

- 2,448
- 1
- 15
- 17
-
Sorry for quick reply, you can use cookie to store the value as well, give it a try – mutanic Sep 06 '18 at 02:33
-
ActiveXObject will not work in Chrome.. I tried some sample using ActiveXObject.. IE the code executes but not in Chrome... – Ziggler Sep 06 '18 at 21:07
Erm is there any reason why you can't just use the HttpRequest? This would be on the server side but you could pass it to the javascript if you needed to?
Page.Request.UserHostName
The one problem with this is it would only really work in an Intranet environment otherwise it would just end up picking up the users Router or Proxy address...

- 618
- 3
- 8