Re: Here is another implementation using IPAddress and IPHostEntry classes

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: 2G (2G_at_pandora.be)
Date: 03/19/04


Date: Fri, 19 Mar 2004 08:40:46 GMT

Hi,

It will depend on your isp. I'm using Telenet (Belgium) so for me,
retrieving my routers ip thru a webpage will not work because the webpage
will display the ip address of the proxy from my isp.
I'm also searching for a solution to retrieve my routers public ip but
haven't found one yet.

Grtz

"Anonieko Ramos" <anonieko@hotmail.com> wrote in message
news:562cba23.0403182223.3d158b9f@posting.google.com...
> Ram,
> If you are in an intranet, this program only shows your
> intranet IP address (e.g. 192.168.xxx.xxx ). I tried
> both programs. The solution by ElreyRonald will correctly
> print the ROUTER address ( bec. it is the IP as 'seen from outside')
>
>
>
>
> "Ram Dash" <rampr2@hotmail.com> wrote in message
news:<ujia$EWDEHA.684@tk2msftngp13.phx.gbl>...
> > I got this from http://www.dotnet247.com/247reference/msgs/1/7651.aspx.
Here
> > is it:
> >
> > using System;
> >
> > using System.Net;
> >
> > namespace ConsoleApplication1
> >
> > {
> >
> > /// <summary>
> >
> > /// Summary description for Class1.
> >
> > /// </summary>
> >
> > class Class1
> >
> > {
> >
> > /// <summary>
> >
> > /// The main entry point for the application.
> >
> > /// </summary>
> >
> > [STAThread]
> >
> > static void Main(string[] args)
> >
> > {
> >
> > string host;
> >
> > host = Dns.GetHostName();
> >
> > Console.WriteLine(host);
> >
> > IPHostEntry i = Dns.GetHostByName(host);
> >
> > foreach (IPAddress a in i.AddressList)
> >
> > {
> >
> > Console.WriteLine(a);
> >
> > }
> >
> > Console.ReadLine();
> >
> > }
> >
> > }
> >
> > }
> >
> > "Anonieko Ramos" <anonieko@hotmail.com> wrote in message
> > news:562cba23.0403181804.29a0fc05@posting.google.com...
> > > I found this code from ElreyRonald. It is a console but
> > > works by referencing another website.
> > >
> > >
> > >
> > >
> > > //--------------------------------------------------------------
> > > // A console application to print IP Address of the current
> > > // workstation (or its router's IP )
> > > //
> > > // Two things are demonstrated here:
> > > // (1) How to get a web page html and
> > > // (2) How to use regular expression to search within a string.
> > > //
> > > // Written by ElreyRonald V. [lambda326@hotmail.com] 2004
> > > //--------------------------------------------------------------
> > >
> > >
> > > using System;
> > > using System.Text.RegularExpressions;
> > > using System.Text;
> > > using System.Net;
> > > using System.IO;
> > >
> > >
> > > namespace Network.Utilities
> > > {
> > >
> > > class GetIp
> > > {
> > > [STAThread]
> > > static void Main(string[] args)
> > > {
> > > // use a website which displays your IP
> > > string urlString = "http://www.getmyipaddress.com";
> > >
> > > // Fetch the html text of the website.
> > > string htmlText = GetPageHtml(urlString);
> > >
> > > // Search for the IP within that page.
> > > string regExpr = @".*>(\d+.\d+.\d+.\d+)</*";
> > > Regex rex = new Regex( regExpr, RegexOptions.None);
> > > if (rex.Match( htmlText).Success )
> > > {
> > > string ip = rex.Match( htmlText).Result("$1").Trim();
> > > Console.WriteLine(ip);
> > > }
> > >
> > > }
> > >
> > > //------------------------------------------------------
> > > // Get the HTML text of a give URL
> > > //------------------------------------------------------
> > > private static String GetPageHtml(string url)
> > > {
> > > StringBuilder sb = new StringBuilder();
> > >
> > > try
> > > {
> > >
> > > WebRequest myRequest = WebRequest.Create(url);
> > >
> > > // Return the response.
> > > WebResponse myHttpWebResponse = myRequest.GetResponse();
> > >
> > > // Gets the stream associated with the response.
> > > Stream receiveStream =
> > > myHttpWebResponse.GetResponseStream();
> > > Encoding encode =
> > > System.Text.Encoding.GetEncoding("utf-8");
> > >
> > > // Pipes the stream to a higher level stream reader with
> > > the required encoding format.
> > > StreamReader readStream = new StreamReader( receiveStream,
> > > encode );
> > >
> > > Char[] read = new Char[256];
> > >
> > > // Reads 256 characters at a time.
> > > int count = readStream.Read( read, 0, 256 );
> > > while (count > 0)
> > > {
> > > // Dumps the 256 characters on a string and displays
> > > the string to the console.
> > > String str = new String(read, 0, count);
> > > //Console.Write(str);
> > > sb.Append(str);
> > > count = readStream.Read(read, 0, 256);
> > > }
> > >
> > > // Releases the resources of the response.
> > > myHttpWebResponse.Close();
> > >
> > > // Releases the resources of the Stream.
> > > readStream.Close();
> > >
> > > }
> > > catch ( Exception )
> > > {
> > > return "";
> > > }
> > >
> > > String strHtml = sb.ToString();
> > > return strHtml.ToString();
> > > }
> > > }
> > > }



Relevant Pages

  • Re: DSL vs. Cable
    ... It depends on the hardware you have, many Cable modems provide a webpage ... at the IP of the device for monitoring, same with some routers. ... call your ISP and ask them. ...
    (microsoft.public.windowsxp.general)
  • The cat came and stayed..
    ... By the time you have finished reading this, I am sure you would have come across the most fascinating networking issue haunted by our friendly ghost Casper. ... Having exploited most of my resources, I finally decided to involve our ISP hoping that this would be the end of it...but it wasn't supposed to be that way. ... But, since the line was given, we felt that we were not only having intermittent problems that required switch reset but also felt that we were not getting the right speed and the data transfer rateswas really not befitting a 100Mbps link. ... Now a strange thing is that when we configure the two routers in 'bridging' mode and start data transfer across, the speed becomes incrementally fast. ...
    (Pen-Test)
  • Re: Accessing Multiple ISPs on the fly
    ... ADSL connection with a second ISP. ... > I am assuming that your WAN connections are going through two differnet ... > workstation to the other subnet if it is used to reset the IP configuration. ... > Its the routers that care. ...
    (microsoft.public.windowsxp.network_web)
  • RE: FreeBSD router two DSL connections
    ... >Subject: RE: FreeBSD router two DSL connections ... suppose I'm a small ISP and I go get a ... and blocked by ATT or Sprint, or my peer routers, in the ... >> letsseenow, these are full duplex 'pipes', can ...
    (freebsd-questions)
  • RE: The cat came and stayed..
    ... I finally decided to involve our ISP hoping that this ... There are two cisco routers across Sites A and B and two media ... Cenzic Hailstorm finds vulnerabilities fast. ...
    (Pen-Test)