0

I am trying this LINK if it is working. I try to debug it in JSFiddle and JSBin using Chrome v55 and IE v7. I know that this is impossible Cuz I read some links before I make this thread. Is there any alternative way for this kind of problem on how to get the mac address of pc?.

<script type="text/javascript">
    var macAddress = "";
    var ipAddress = "";
    var computerName = "";
    var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}");
    e = new Enumerator(wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"));
    for(; !e.atEnd(); e.moveNext()) {
        var s = e.item(); 
        macAddress = s.MACAddress;
        ipAddress = s.IPAddress(0);
        computerName = s.DNSHostName;
    } 
</script>
<input type="text" id="txtMACAdress" />
<input type="text" id="txtIPAdress" />
<input type="text" id="txtComputerName" />

<script type="text/javascript">
    document.getElementById("txtMACAdress").value = unescape(macAddress);
    document.getElementById("txtIPAdress").value = unescape(ipAddress);
    document.getElementById("txtComputerName").value = unescape(computerName);
</script>
KiRa
  • 924
  • 3
  • 17
  • 42
  • Do you need the local IP or external IP address of the device? Most of this stuff can't be circumvented in the browser for security reasons, but you can get the external IP via PHP with some drawbacks if all else fails. – ppajer Feb 01 '17 at 02:37
  • @ppajer I don't know how to use PHP. I am using asp.net mvc3 – KiRa Feb 01 '17 at 02:40
  • Every server side language should have some way to get the request's IP. A little digging around got me [this](https://www.dotnetperls.com/ip), but I'm not familiar with .NET so can't tell whether it works or not. From there it should be trivial to get that value into a JS variable. – ppajer Feb 01 '17 at 02:50
  • @ppajer If IP address of the PC I can get it [here](https://jsfiddle.net/m9z296oa/1/). – KiRa Feb 01 '17 at 02:53
  • @ppajer its okay now I can get the mac address of the PC. – KiRa Feb 01 '17 at 05:07
  • Dear friend, I am trying to use your code but I am getting an error, please help. Uncaught ReferenceError: GetObject is not defined GetObject("winmgmts:{impersonationLevel=impersonate}"); – Gautam Kumar Sahu May 28 '18 at 06:21

0 Answers0