Skip to content

Instantly share code, notes, and snippets.

@JohnRuddy
Last active January 30, 2017 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnRuddy/819ed163d07cb7e684035f50efb85f46 to your computer and use it in GitHub Desktop.
Save JohnRuddy/819ed163d07cb7e684035f50efb85f46 to your computer and use it in GitHub Desktop.
Check List of Status of List of Websites
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace WebsiteChecker
{
class Program
{
static void Main(string[] args)
{
var urls = new List<string>();
// read in a series of websites
using (var reader = new StreamReader("WebsiteList.txt"))
{
while (!reader.EndOfStream)
{
urls.Add(reader.ReadLine());
}
}
// Track the status of each site
using (FileStream fs = new FileStream("Results.txt", FileMode.Append, FileAccess.Write))
using (StreamWriter sw = new StreamWriter(fs))
{
foreach (var url in urls)
{
HttpWebResponse httpRes = null;
var httpReq = (HttpWebRequest)WebRequest.Create("http://" + url);
httpReq.AllowAutoRedirect = false;
try
{
httpRes = (HttpWebResponse)httpReq.GetResponse();
sw.WriteLine("{0} - {1}", url, httpRes.StatusCode);
httpRes.Close();
}
catch (Exception)
{
sw.WriteLine(url + " - Error");
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment