How to find my external IP address

If you computers are sitting behind a router/firewall, then running Ipconfig would not give you the external IP address. One can use for ad-hoc queries, but if you want to automate the checks you might want something simpler and easier to parse. The followings are the options I found.

The c# code to find out your external IP:

public string GetPublicIP() {
    String direction = "";
    WebRequest request = WebRequest.Create("");
    using (WebResponse response = request.GetResponse())
    using (StreamReader stream = new StreamReader(response.GetResponseStream())) {
        direction = stream.ReadToEnd();
    //Search for the ip in the html
    int first = direction.IndexOf("Address: ") + 9;
    int last = direction.LastIndexOf("</body>");
    direction = direction.Substring(first, last - first);
    return direction;