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 />
208.106.78.22
Without the -q switch the output is:
Current IP CheckCurrent IP Address: 206.108.78.2
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,
mgd
Comments
-
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
Cheers,
blue_raptor0 -
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}'0 -
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: 208.106.8.22
AWK produces: 208.106.8.22
Thank you kindly,0 -
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 10 -
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.0
Categories
- All Categories
- 177 LFX Mentorship
- 177 LFX Mentorship: Linux Kernel
- 769 Linux Foundation IT Professional Programs
- 379 Cloud Engineer IT Professional Program
- 175 Advanced Cloud Engineer IT Professional Program
- 75 DevOps IT Professional Program - Discontinued
- 7 DevOps & GitOps IT Professional Program
- 102 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 7 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 16 Cloud & Containers Training
- 2 Cybersecurity Training
- 2 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 2 Networking Training
- 2 Open Source Best Practice Training
- 4 System Administration Training
- 1 System Engineering Training
- 2 Web & Application Development Training
- 796 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 91 Storage
- 771 Linux Distributions
- 81 Debian
- 68 Fedora
- 23 Linux Mint
- 13 Mageia
- 24 openSUSE
- 151 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 466 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 79 Network Management
- 101 System Management
- 46 Web Management
- 127 Mobile Computing
- 20 Android
- 92 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 400 Off Topic
- 124 Introductions
- 32 Study Material
- 1K Programming and Development
- 310 Kernel Development
- 705 Software Development
- 1K Software
- 409 Applications
- 182 Command Line
- 5 Compiling/Installing
- 70 Games
- 318 Installation
- Archived
- 183 Small Talk
- 2 LFD140 Class Forum
- 1.4K LFS258 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)