LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-07-2009, 03:20 PM   #16
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122

Quote:
Originally Posted by Sergei Steshenko View Post
Why does IP address has to be returned through 'ping' in the first place ? I.e. why not to resolve hosts without 'ping' ?
Exactly, see post #2.

Ping really isn't the tool for the job.
 
Old 05-07-2009, 04:08 PM   #17
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS7
Posts: 267

Rep: Reputation: 58
try this:

host yahoo.com |grep -m 1 address|cut -d \ -f 4

(Note there is two spaces between the \ and the -)

Last edited by david1941; 05-07-2009 at 04:11 PM. Reason: Dosen't seem to print right)
 
1 members found this post helpful.
Old 05-07-2009, 07:13 PM   #18
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
@OP, read the awk manual. the answers are there on what is NR, gsub.
 
Old 11-23-2015, 12:27 PM   #19
hukona
LQ Newbie
 
Registered: Nov 2015
Posts: 3

Rep: Reputation: Disabled
Quote:
Originally Posted by guest View Post
Is there a simple way to return an IP by pinging a hostname? Ideally it takes low resources because I have a lot of hostnames to ping!

Thanks in advance
just try typing:

ping -c1 -q yahoo.com | grep 'PING' | cut -d \ -f 3 | egrep -o '[0-9.]+'

and you will get the result

98.138.253.109

I just used the method offered by david1941 on post #17 and applied to your post #7 changing the grep search from '(' to 'PING' because this word only appears in the line that contains ip you need.


I don't know why but ping seems to be more fast than other, at least as I have compared with hosts.

This worked in linuxmint 17.2 nokia n9, and on terminal android 4.1.2 rooted phone.

Last edited by hukona; 11-23-2015 at 12:43 PM. Reason: add data
 
Old 11-23-2015, 02:48 PM   #20
LanceTaylor
Member
 
Registered: Nov 2015
Location: Houston, Texas, US
Distribution: RHEL/CentOS, Debian/Linux Mint, SLES
Posts: 40

Rep: Reputation: 19
Quote:
Originally Posted by guest View Post
I'd like a command that returns ONLY the IP, so something that parses the mumbo jumbo results and outputs only:
1.2.3.4

Is what I'm asking for
Code:
host domain.com | head -n1 | awk '{print $4}'
 
Old 02-03-2018, 09:36 PM   #21
Mayankgirdhar143
LQ Newbie
 
Registered: Feb 2018
Posts: 1

Rep: Reputation: Disabled
How we can do same task in windows

How we can do same task in windows ?
 
Old 02-04-2018, 01:48 AM   #22
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Welcome to LQ!

You have replied to a thread which has been inactive for more than two years. You should consider opening your own thread with a description of your specific task to attract the attention of currently active members with the most relevant knowledge.

Please also review the Site FAQ for guidance in asking complete and well formed questions. The more information you provide with your question, the better others will be able to provide help!
 
Old 02-04-2018, 05:29 AM   #23
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
If I reply now after the thread showed in "latest threads", is it considered necroposting as well?

Anyway, no one seems to have thought about this one:
Code:
jlinkels@donald-pc:~$ fping -a -A -q www.google.com
216.58.219.68
Just to complete the discussion

jlinkels
 
Old 02-07-2018, 09:06 PM   #24
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I so rarely see fping I'd forgotten it exists...
Using older ping
Code:
ping -c 1 fp102.prod.sac.int.threatmetrix.com |head -1|awk '{print $3}|tr -d '()'
is one way.

In re very old comments about eg dig, nslookup etc; maybe the OP wanted IPs for active/up machines only; DNS just tells you what m/cs it knows of - they might not be up/reachable
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Return MAC Address with Ping Critcho Linux - Networking 16 05-04-2011 11:40 AM
Ping Return Remote Host Information qwerty_tele Linux - Security 3 11-24-2008 11:05 AM
can't ping local IP address but can ping remote hosts rob_xx17 Linux - Networking 4 12-02-2006 08:39 AM
Return true or false if I have ping reply Menestrel Programming 4 11-29-2004 12:40 AM
windows 98 m/c ping to ip address of red hat server but fails to ping hostname ravilohot Linux - Networking 2 09-07-2004 04:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration