0

I'm very new to Javascript world. Just curious to know that how to run the below command in javascript function and display in alert box.

ipconfig

I'm not trying it for any real world application. Just wanna know is that possible and how does it work internally.

Expected:

<script>
   function showAlert(){
    alert(ipconfig);
    console.log(ipconfig); // For object
   }    
</script>

It's purely for my understanding and If it's not possible then how webRTC is enabling the user to get the same details?

ArrchanaMohan
  • 2,314
  • 4
  • 36
  • 84
  • Does this answer your question? [How to execute shell command in Javascript](https://stackoverflow.com/questions/1880198/how-to-execute-shell-command-in-javascript) – Gokulakannan T Jan 29 '20 at 06:49

1 Answers1

0

If you are running a NodeJS server, then it is possible via child_process module.

Below code is the example for Linux, you can change code suitable for windows

var process = require('child_process');
process.exec('ifconfig',function (err,stdout,stderr) {
    if (err) {
        console.log("\n"+stderr);
    } else {
        console.log(stdout);
    }
});

However, for IE browser we can do something like that

var oShell = new ActiveXObject("Shell.Application");

var commandtoRun = "C:\\Winnt\\Notepad.exe";
if (inputparms != "") {
  var commandParms = document.Form1.filename.value;
}

// Invoke the execute method.  
oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");

NOTE: Not sure ActiveXObject will work in your current window version (8/10);

For more details,Question you can go to this link on StackOverflow

Not A Bot
  • 2,474
  • 2
  • 16
  • 33
  • Just curious why that It didn't support for Chrome and FF browser. Just heard that AcriveXobject only on IE. My intention is to enable it for chrome browser and Is that possible to call node.js code inside html? Just assume that if we are running the server (node.js) on linux box and trying to fetch ipconfig which is not work. so is it possible to handle it in browser? – ArrchanaMohan Jan 29 '20 at 06:52
  • See browsers don't allow to access anything outside the view that they are intended to show to the user, as allowing users to access anything outside the view can hard the system(Security, privacy, etc.). The example could be if you select a file(image or a file) from the HTML tag `````` and check-in javascript, you will see FAKE path for that file(image or a file). So from within the browser, it is ***not possible*** to execute ```CMD``` command. – Not A Bot Jan 29 '20 at 06:58
  • ```ActiveXObject``` has many issues related to security, that's why you cannot use it in **Chrome** or **FF** other than **IE**. Here is a good overview for ActiveXObject https://developer.mozilla.org/en-US/docs/Web/JavaScript/Microsoft_Extensions/ActiveXObject So you need to have a server like **NodeJS** then on a server only you can run your ```ipconfig``` command. I suppose there are come HACKS to run or impersonate ```ActiveXObject``` for **Chrome or FF** but it is not advisable. – Not A Bot Jan 29 '20 at 07:03