JavaScript端口扫描工具

2022-10-26 17:34:59 浏览数 (1)

一个利用JavaScript实现的简易域名端口扫描工具,反馈目标地址的端口状态,因为是课设需要,自己也用不到,就没怎么深入研究,只是简单的加了个正则验证,支持自定义端口扫描和按端口范围扫描。

演示地址:点击访问端口扫描器

Github地址:https://github.com/Yue-Zeyi/port-check

截图

原理

核心代码

代码语言:javascript复制
var AttackAPI = {};
AttackAPI.PortScanner = {};
AttackAPI.PortScanner.scanPort = function (callback, target, port, timeout) {
  var timeout = timeout == null ? 100 : timeout;
  var msg = new Image();
  msg.onerror = function () {
    if (!msg) return;
    msg = undefined;
    callback(target, port, ' --- 开启');
  };

  msg.onload = msg.onerror;
  msg.src = 'http://'   target   ':'   port;

  setTimeout(function () {
    if (!msg) return;
    msg = undefined;
    callback(target, port, ' --- 关闭');
  }, timeout);
};
AttackAPI.PortScanner.scanTarget = function (callback, target, ports, timeout) {
  for (index = 0; index < ports.length; index  )
    AttackAPI.PortScanner.scanPort(callback, target, ports[index], timeout);
};
var result = document.getElementById('result');
var callback = function (target, port, status) {
  result.value  = target   ':'   port   status   ' n';
};
var scan = function (form) {
  // 清空结果
  var obj = document.getElementById('result');
  obj.value = '';
  AttackAPI.PortScanner.scanTarget(
    callback,
    form.target.value,
    form.port.value.split(','),
    form.timeout.value
  );
};

0 人点赞