Skip to content

Instantly share code, notes, and snippets.

@rhwy
Created May 29, 2014 10:57
Show Gist options
  • Save rhwy/e33f7de0804abb48040a to your computer and use it in GitHub Desktop.
Save rhwy/e33f7de0804abb48040a to your computer and use it in GitHub Desktop.
a small working sample of a tool as simple as possible using webclient (and async)
namespace nurl1
{
class Program
{
public static void Main(string[] args)
{
if(args.Length<1 || !(Regex.Match(args[0],@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b").Success))
throw new ArgumentException("not a valid ip number");
Console.WriteLine("Country for ip [{0}]",args[0]);
new WebClient()
.DownloadStringTaskAsync("http://api.hostip.info/country.php?ip=" + args[0])
.ContinueWith((t)=>{
Console.WriteLine(t.Result);
Console.Write("Press any key to continue . . . ");
});
Console.WriteLine("----------------------------");
Console.ReadKey(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment