1

I have been trying to make a simple program that grabs the ip text of ipchicken.com. However, when I run it I get a bunch of HTML and not the IP. Here is what I have so far.

{
WebClient something = new WebClient();
string text = something.DownloadString("http://ipchicken.com");
label1.Text = text;
}

What am I doing wrong?

  • Seems you're searching wrong :) Have a look [here](http://stackoverflow.com/questions/2462170/c-get-ip-address-from-domain-name) . "Dns.GetHostAddresses" is your solution – Noctis Mar 29 '14 at 03:55
  • @Noctis wouldn't that give the ipaddress of ipchicken.com ? ipchicken gives you your ipaddress when you visit it. I think he wants to know capture the ip displayed on the website. OP, can you clarify if I understood correctly ? – anu Mar 29 '14 at 03:57
  • you said: `simple program that grabs the ip text`, I guess the IP address is your ip ... maybe you want to ask the question differently ? – Noctis Mar 29 '14 at 03:59
  • @Noctis I didn't ask the question. LOL. I am just trying to help ...just like you. – anu Mar 29 '14 at 04:02
  • @Anupam Lol ... my bad ... I figured it's the guy asking the question that replied ... my bad :) ...yep, from what **he** said, I figured that's what he want ... – Noctis Mar 29 '14 at 04:04
  • I want the ip displayed on the page not the ip chicken ip –  Mar 29 '14 at 04:28

1 Answers1

0

you need to scrape the html for get the ip.

You'd need to use load the document into a HTML Parser and reach and extract the ip which is in body.table.tr.td.p.b

Probably this Parsing HTML with c#.net will help you figure out how to parse.

Community
  • 1
  • 1
anu
  • 1,017
  • 1
  • 19
  • 36
  • I still don't really understand :| –  Mar 29 '14 at 15:10
  • @gdawgholmes If you read the html that you get, closely, you will see that the ip address is "embedded" deep inside the massive pile of html. More specifically, you will find the IP-address that you see on your web-browser inside the 2nd 3rd

    tag. Just examine the html output you get line by line. And trace the path I just mentioned. You will find what you need

    – anu Mar 29 '14 at 15:28
  • I have htmlagility, so what would the code be for that? I think that if I saw the exact code and looked at it I would get a better idea of how to use it. –  Mar 30 '14 at 03:05
  • In the link I gave you, if you look at the top answer, the guy "extracts" all anchor tags from html. You need to extract all paragraph tags instead. Just substitute the anchor tag with para tag in his code and you ll be good to go. Let me know if you need further help – anu Mar 30 '14 at 08:59