标签:creat try contains exp orb 机器 def byte exce
[源码]K8 Cscan模块 C#扫描内网主机IP/机器名/Banner/网页标题源码
Cscan内置Delphi、VC、.NET例子,需要更多功能,请自行添加完善
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
namespace CscanDLL
{
public class scan
{
public static string run(string ip)
{
if (string.IsNullOrEmpty(ip))
return "";
else
{
string hostName = "";
//return ip;
//return System.Net.Dns.GetHostByAddress(ip).HostName;
//192.11.22.10 Microsoft-IIS/10.0 IIS Windows
//192.11.22.1 H3C-Miniware-Webs ER3200G2
return ip + "\t" + getURLbanner(ip) + "\t" + GetTitle(getHtml("http://" + ip,2));
//return ip + "\t" + hostName + "\t[" + getURLbanner(ip) + "]\t[" + GetTitle(getHtml("http://" + ip)) + "]";
//return ip + "\t" + System.Net.Dns.GetHostByAddress(ip).HostName;
}
}
private static string getURLbanner(string url)
{
url = "http://" + url;
try
{
var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
req.Method = "HEAD";
req.Timeout = 10000;
var res = (HttpWebResponse)req.GetResponse();
if (res.StatusCode == HttpStatusCode.OK || res.StatusCode == HttpStatusCode.Forbidden || res.StatusCode == HttpStatusCode.Redirect || res.StatusCode == HttpStatusCode.MovedPermanently)
{
return res.Server;
}
//res.Close();
return res.Server;
}
catch (WebException ex)
{
return "";
}
}
private static string GetTitle(string html)
{
String regex = @"<title>.+</title>";
String title = Regex.Match(html, regex).ToString();
title = Regex.Replace(title, @"[\""]+", "");
return title;
}
private static string getHtml(string url)
{
try
{
if (!url.ToLower().Contains("https://") && !url.ToLower().Contains("http://"))
url = "http://" + url;
WebClient web = new WebClient();
byte[] buffer = web.DownloadData(url);
return Encoding.UTF8.GetString(buffer);
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}
编译成netscan.dll后,放置Cscan.exe同目录即可(netscan.dll优先级最高,无须删除其它插件)
ip.txt填上当前IP段或内网多个IP段,执行Cscan.exe。
Cscan20对应.net 2.0编译,所以编译的DLL也要对应版本
实战使用哪个版本,由目标系统已安装.net版本来决定。
结果如图

[源码]K8 Cscan插件 C#获取内网主机IP/机器名/Banner/网页标题
标签:creat try contains exp orb 机器 def byte exce
原文地址:https://www.cnblogs.com/k8gege/p/10519512.html