先说说目的。

为了注册一个域名,是数字类型的

大约在四位数,看看是不是所有的.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;
        }
    }
}

没有注释哈,凑合看吧,想深入的自己研究下。

 

可能写的不好多指教哈! 可以Google搜索下。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2021-11-29
  • 2021-10-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-10
  • 2021-06-15
  • 2021-08-05
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案