先说说目的。
为了注册一个域名,是数字类型的
大约在四位数,看看是不是所有的.com都被注册了。一个一个尝试太麻烦了。所以有了这个。
看代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace TestDomain
{
class Program
{
static void Main(string[] args)
{
string url = "http://www.xxxx.com/domain.aspx?id=";
string filePath = "d:\\page.txt";
string isNotRegister = "No match for";
string pageDate = string.Empty;
for (int i = 6700; i < 10000; i++)
{
pageDate = GetDomain(url + i + ".com");
if (pageDate.Contains(isNotRegister)) //如果存在这样字样证明没有被注册写入文件
{
try
{
using (StreamWriter sw = new StreamWriter(filePath, true))
{
sw.WriteLine(i + ".com");
sw.Close();
}
}
catch (IOException e) {
Console.WriteLine(e.ToString());
}
}
Console.WriteLine(i.ToString());
}
}
static string GetDomain(string url)
{
string pageDate = string.Empty;
try
{
WebClient myClient = new WebClient();
myClient.Credentials = CredentialCache.DefaultCredentials;
pageDate = myClient.DownloadString(url);
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
return pageDate;
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace TestDomain
{
class Program
{
static void Main(string[] args)
{
string url = "http://www.xxxx.com/domain.aspx?id=";
string filePath = "d:\\page.txt";
string isNotRegister = "No match for";
string pageDate = string.Empty;
for (int i = 6700; i < 10000; i++)
{
pageDate = GetDomain(url + i + ".com");
if (pageDate.Contains(isNotRegister)) //如果存在这样字样证明没有被注册写入文件
{
try
{
using (StreamWriter sw = new StreamWriter(filePath, true))
{
sw.WriteLine(i + ".com");
sw.Close();
}
}
catch (IOException e) {
Console.WriteLine(e.ToString());
}
}
Console.WriteLine(i.ToString());
}
}
static string GetDomain(string url)
{
string pageDate = string.Empty;
try
{
WebClient myClient = new WebClient();
myClient.Credentials = CredentialCache.DefaultCredentials;
pageDate = myClient.DownloadString(url);
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
return pageDate;
}
}
}
没有注释哈,凑合看吧,想深入的自己研究下。
可能写的不好多指教哈! 可以Google搜索下。