Skip to content

Instantly share code, notes, and snippets.

@thebitbrine
Created April 29, 2019 13:10
Show Gist options
  • Save thebitbrine/c614f4fde3f443a4eb58cf2dbd657ecb to your computer and use it in GitHub Desktop.
Save thebitbrine/c614f4fde3f443a4eb58cf2dbd657ecb to your computer and use it in GitHub Desktop.
Fetches external IP address from google.
public string GoogleWhatsMyIP()
{
var Response = new System.Net.WebClient() { Encoding = System.Text.Encoding.UTF8 }.DownloadString("https://www.google.am/search?q=whats+my+ip&hl=en");
var m = new System.Text.RegularExpressions.Regex("((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?![\\d])").Match(Response);
if (m.Success)
return m.Groups[1].ToString();
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment