Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C#] Get External IP through Webrequests [Intermediate]
#1
This is poorly written but does the job. Didn't bother with timeouts, which probably need to be added. And there probably is a faster way of getting your IP but this is the fastest way I could think of.

Imports:
Code:
using System.Net;
using System.IO;

Code:
Code:
static string IP()
        {
            //http://www.whatismyip.com/automation/n09230945.asp
            HttpWebRequest WhatIsMyIP_Request = (HttpWebRequest)HttpWebRequest.Create("http://www.whatismyip.com/automation/n09230945.asp");
            HttpWebResponse WhatIsMyIP_Response = (HttpWebResponse)WhatIsMyIP_Request.GetResponse();
            StreamReader WhatIsMyIP_Source = new StreamReader(WhatIsMyIP_Response.GetResponseStream());
            return WhatIsMyIP_Source.ReadToEnd();
        }

Usage:
Code:
Console.WriteLine(IP());
Reply


Messages In This Thread
[C#] Get External IP through Webrequests [Intermediate] - by Mike - 08-31-2010, 12:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [C#] Simple RC2 Encryption/Decryption [Intermediate] Mike 3 3,626 12-21-2010, 11:38 PM
Last Post: ZxPwn420
  [C#] Loading/Writing XML Files [Intermediate] Mike 4 2,341 09-29-2010, 10:17 AM
Last Post: Fitz-
  [C#] Get External IP. wchar_t 3 1,922 08-14-2010, 03:57 PM
Last Post: wchar_t

Forum Jump:


Users browsing this thread: 2 Guest(s)