0

I am trying to display the nslookup value from the javascript function, that return the nslookup value back to the html while loading the page.

i have following script in the html page:

<html>
<style type="text/css">
    .Table
    {
        display: table;
    }
    .Title
    {
        display: table-caption;
        text-align: center;
        font-weight: bold;
        font-size: larger;
    }
    .Heading
    {
        display: table-row;
        font-weight: bold;
        text-align: center;
    }
    .Row
    {
        display: table-row;
    }
    .Cell
    {
        display: table-cell;
        border: solid;
        border-width: thin;
        padding-left: 20px;
        padding-right: 20px;
    }
</style>
<body onload="myFunction()">
<h1>"The dns ip is: " <span id="myID"></span></h1>

    <div class="Heading">
        <div Class="Cell">
            <p>G</p>
        </div>
        <div Class="Cell">
            <p>facebook.com</p>
        </div>
        <div id="test">
            <span id="h" class="Cell">
                <p>H</p>
            </span>
            <span id="e" class="cell">
                <p>E</p>
            </span>
           <span id ="Time" class="Cell">   
                <P> </P>                
             </span>
        </div>


        <div Class="Cell">
            <p></p>
        </div>
    </div>

</body>



<button type="button" onclick="myFunction()">Refresh</button> 

<script>
function myFunction()
 {

    //document.body.style.backgroundColor = "red";
    document.getElementById("h").style.background="green";
    const dns = require('dns');
    var status="";
    dns.lookup('facebook.com', function(err, result){
     var status = result;
    });
     document.getElementById("Time").innerHTML=status;
}
</script> 

</html>



Expected: I expect to get the dns value for the url facebook.com to be returned and displays in "The dns ip is:" field

Actual: Nothing is returning from the script to display over there

Appreciate if anyone can help on this?

HariUmesh
  • 71
  • 1
  • 9

1 Answers1

-1
function myFunction()
 {
    const dns = require('dns');
    dns.lookup('https://facebook.com', function(err, result){
     var status = result
     document.getElementById("myID").innerHTML=status;
    });
}
Abhishek Mishra
  • 192
  • 1
  • 7
  • Thank You Abhishek Mishra and Joel for sharing the input.. However its not working as expected. Could you please update those in the code i shared, so that i can compare where the changes got effected. Appreciate for your help. – HariUmesh Aug 27 '19 at 05:58
  • @HariUmesh: Can you please tell me if you are getting any error? – Abhishek Mishra Aug 27 '19 at 06:15
  • HI Abhishek, iam not getting any value from the function and no ip displays in the respective field – HariUmesh Aug 27 '19 at 06:19
  • @HariUmesh: Can you share the screenshot of console? – Abhishek Mishra Aug 27 '19 at 06:22
  • @Ahishek, iam not in a situation to share the screen shot. However, When i tested for 'https://facebook.com' , it's not returning anything says undefined. When i removed the 'https://', iam getting the ip – HariUmesh Aug 27 '19 at 07:57
  • So that's the return of the address parameter at dns npm package, did you get the element well ? Status is a. String ? – Joel Garcia Nuño Aug 27 '19 at 09:14
  • Hi @JoelGarciaNuño, I have updated above code and while executing the script, the result for the dns.lookup returns nothing here. Here i just added onclick event to execute it. Could you please look in to this? Much appreciated if can help on this. Thank You – HariUmesh Aug 27 '19 at 09:49