Welcome to the Linux Foundation Forum!

using wget, checkip.dyndns.org, and sed


I am trying to get my external Ip using cygwin on a Windows 7 box. I am almost there but I am having an issue with the sed substitution syntax. As you see, I am getting the IP, but I don't want the part of the output.

C:\>wget -q http://checkip.dyndns.org -O index1.html && sed "s/.*:\(.*\)<.*/\1/" index1.html<br />

Without the -q switch the output is:

Current IP CheckCurrent IP Address:

How do I have to change the sed command? Instead of creating the index1.html file, I also tried unsuccessfully to use pipe and grep, but failed to get that working properly. Alternative approaches would also be appreciated, but I would like to know what I am doing wrong with the sed commands. I have tried many different variations, but just can't seem to get just the IP address.

Thank you,



  • blue_raptor
    I am not sure if SED is the string manipulator to use for this kind of outputs.

    I used cut and Below command could work for you..

    wget -q checkip.dyndns.org -O index.html && cat index.html | cut -d '>' -f 7 | cut -d '<' -f 1

  • odlevakp
    or with awk it could look like this :)
    wget -q checkip.dyndns.org -O index2.html && awk '{print $6}' index2.html | awk -F'<' '{print $1}'
  • mgd
    mgd Posts: 3
    Hi, Karma

    The "cut" and "awk" commands used in your examples produced slightly different results, but each example was most helpful in illustrating the basics of these two commands. I now have two command options for filtering output/text.

    Cut produces: Current IP Address:

    AWK produces:

    Thank you kindly,
  • blue_raptor
    below is for getting only IP using CUT

    wget -q checkip.dyndns.org -O index.html && cat index.html|cut -d ' ' -f 6 | cut -d '<' -f 1
  • jabirali
    jabirali Posts: 157
    You could also skip the intermediate file by using curl instead of wget, which is a command whose main use is to pipe a web page as a text stream to some other command. Some systems come without curl preinstalled, but it's quite common (and useful) in scripts, so in that case I recommend installing it.
    curl -s checkip.dyndns.org | sed 's/.*<body>Current IP Address: //;s/<\\/body>.*//'
    Note the semicolon used in the argument to sed; it's used to separate different expressions when you want to do multiple substitutions without calling sed multiple times.


Upcoming Training