3,881
社区成员
发帖
与我相关
我的任务
分享
foreach (var line in path)
{
if (line.IndexOf("https") != -1)
{
string a = line.Substring(8, line.Replace("://", "").IndexOf("/") - 5);//截取获取网站域名
doma = a;
}
else if (line.IndexOf("http") != -1)
{
string a = line.Substring(7, line.Replace("://", "").IndexOf("/") - 4);//截取获取网站域名
doma = a;
}
else if (line.IndexOf("http") == -1 && line.IndexOf("https") == -1 && line.IndexOf("com") != -1)
{
string a = line.Substring(0, line.IndexOf("com") + 3);//截取获取网站域名
doma = a;
}
else
{
string a = line.Substring(0, line.IndexOf("cn") + 2);//截取获取网站域名
doma = a;
}
if (line.IndexOf(".") == -1)
{
doma = line;
}
try
{
//Ping 实例对象;
Ping pingSender = new Ping();
//ping选项;
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "ping test data";
byte[] buf = Encoding.ASCII.GetBytes(data);
//调用同步send方法发送数据,结果存入reply对象;
PingReply reply = pingSender.Send(doma, 120, buf, options);
DateTime.Now.ToString();
if (reply.Status == IPStatus.Success)
{
String title = GetWebClient(line);//获取网站的title
//XML格式保存文本
String www = "<wz>\r\n <url>" + doma + "</url>\r\n <tiem>" + DateTime.Now.ToString() + "</tiem>\r\n<ifopen>" + CheckUrlVisit(line) + "</ifopen> <title>" + title + "</title>\r\n<ip>" + reply.Address + "</ip>\r\n<ftiem>" + reply.RoundtripTime + "</ftiem>\r\n<stiem>" + reply.Options.Ttl + "</stiem>\r\n<buffer>" + reply.Buffer.Length + "</buffer>\r\n <date>" + reply.Options.DontFragment + "</date>\r\n</wz>\r\n ";
p += www;
}
else
{
p += "<wz>\r\n<url>" + doma + "</url>\r\n<tiem>" + DateTime.Now.ToString() + "</tiem>\r\n<ifopen>" + CheckUrlVisit(line) + "</ifopen>\r\n<title>获取失败!!!</title>\r\n<ip>获取失败!!!</ip>\r\n<ftiem>获取失败!!!</ftiem>\r\n<stiem>获取失败!!!</stiem>\r\n<buffer>获取失败!!!</buffer>\r\n<date>获取失败!!!</date>\r\n</wz>\r\n"; ;
}
}
catch
{
p += "<wz>\r\n<url>" + doma + "</url>\r\n<tiem>" + DateTime.Now.ToString() + "</tiem>\r\n<ifopen>" + CheckUrlVisit(line) + "</ifopen>\r\n<title>获取失败!!!</title>\r\n<ip>获取失败!!!</ip>\r\n<ftiem>获取失败!!!</ftiem>\r\n<stiem>获取失败!!!</stiem>\r\n<buffer>获取失败!!!</buffer>\r\n<date>获取失败!!!</date>\r\n</wz>\r\n"; ;
}
}
#include <windows.h>
#include <stdio.h>
#include <string.h>
char YN(int k) {
FILE *f;
char fn[40];
char ln[80];
char yn;
int n;
yn='N';
sprintf(fn,"d:\\ping%d.txt",k);
f=fopen(fn,"r");
if (NULL!=f) {
n=0;
while (1) {
if (NULL==fgets(ln,80,f)) break;//
if (strstr(ln,"ms ")) {
yn='Y';
break;//
}
n++;
if (n>=4) break;//
}
fclose(f);
}
return yn;
}
void main(int argc,char **argv) {
char cmdstr[256];
int i;
int IP[3];
char c;
if (argc<2) {
USAGE:
printf("Usage example:\n %s 192.168.60.\nto test 192.168.60.1-254\n",argv[0]);
return;
}
if (4==sscanf(argv[1],"%d.%d.%d%c",&IP[0],&IP[1],&IP[2],&c)) {
if (0<=IP[0] && IP[0]<=255
&& 0<=IP[1] && IP[1]<=255
&& 0<=IP[2] && IP[2]<=255
&& '.'==c) {
for (i=1;i<255;i++) {
sprintf(cmdstr,"cmd /c ping %s%d -n 1 -w 1000 >d:\\ping%d.txt",argv[1],i,i);
WinExec(cmdstr,SW_HIDE);
}
Sleep(3000);
for (i=1;i<255;i++) {
printf("%c %s%d\n",YN(i),argv[1],i);
}
Sleep(3000);
WinExec("cmd /c del /q d:\\ping*.txt",SW_HIDE);
} else goto USAGE;
} else goto USAGE;
}