使用JavaScript查找DNS并查找特定域名的IP

时间:2014-06-03 06:45:38

标签: javascript jquery

我是javascript的新手。我试图这样做:

<head>
    <title>DNS Check</title>
    <script language="javascript" src="dnscheck.js"></script>
</head>
<body>
    <table width="0%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td align="right">DOMAIN:</td>
            <td align="left">
                <input type="text" id="domainTxt" name="domainTxt">
            </td>
        </tr>
        <tr>
            <td align="center">
                <input type="submit" id="submitBtn" value="Submit" onclick="dnsCheck('domainTxt')">
            </td>
        </tr>
    </table>
</body>

dnscheck.js文件:

<script language="javascript" src="/home/dns.js" type="text/javascript">
    // dns.js is file downloaded from  node.js 

    function dnsCheck(domainTxt) {
        var dns = require('dns'); // syntax error 

        dns.resolve4('www.google.com', function(err, addresses) {
            if (err) throw err;

            console.log('addresses: ' + JSON.stringify(addresses));

            addresses.forEach(function(a) {
                dns.reverse(a, function(err, domains) {
                    if (err) {
                        throw err;
                    }

                    console.log('reverse for ' + a + ': ' + JSON.stringify(domains));
                });
            });
        });
    }
</script>

但我在var dns = require('dns');

时收到语法错误

0 个答案:

没有答案