Pinging a domain


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pinging a domain
# 1  
Old 12-29-2011
Pinging a domain

how can you ping a domain and store the ip?
like given a url in a variable $url
how can i ping it?

also how can i find the local server's ip address on a cpanel server?
(i have multiple servers and didnt want to hard code it in)

(basically i want to check the domain accounts on the server, ping them and see if they are resolving to the local server ip)
# 2  
Old 12-29-2011
Please post your exact Operating System and version and state what Shell you prefer.
There is so much variation in TCP/IP commands that there is no generic answer.

There seems to be a Forum on the cPanel site:
http://www.cpanel.net/
# 3  
Old 12-29-2011
centos
and my shell is like this:

#!/bin/bash

thanks!

---------- Post updated at 10:35 PM ---------- Previous update was at 02:37 PM ----------

given any domain domain.com
do you know how to ping the domain to get its ip from a shell script?
thanks
# 4  
Old 12-29-2011
Not tested

Code:
 
a="www.google.com"
ip=$(host $a | awk '/has add/ {print $4;exit}')
[ "$ip" -eq "" ] && echo "Not Valid Domain" || echo "IP address is : $ip"

# 5  
Old 12-30-2011
Something like this?
Code:
val=$( ping $url -c 1 )
IP=$(echo $c | awk -F'[()]' '{print $6}')

If ping succeeded, the IP will have the ip address.

If your OS is solaris, then this will not work!

HTH
--ahamed
# 6  
Old 12-30-2011
Quote:
Originally Posted by itkamaraj
Not tested

Code:
 
a="www.google.com"
ip=$(host $a | awk '/has add/ {print $4;exit}')
[ "$ip" -eq "" ] && echo "Not Valid Domain" || echo "IP address is : $ip"


host doesnt give the right ip of google

for example, Google is 74.125.227.49 (from a ping)

but
host google.com says:
google.com has address 173.194.34.52
google.com has address 173.194.34.48
google.com has address 173.194.34.49
google.com has address 173.194.34.50
google.com has address 173.194.34.51
google.com mail is handled by 30 alt2.aspmx.l.google.com.
google.com mail is handled by 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.
google.com mail is handled by 10 aspmx.l.google.com.
google.com mail is handled by 20 alt1.aspmx.l.google.com.

---------- Post updated at 05:08 AM ---------- Previous update was at 05:01 AM ----------

Quote:
Originally Posted by ahamed101
Something like this?
Code:
val=$( ping $url -c 1 )
IP=$(echo $c | awk -F'[()]' '{print $6}')

If ping succeeded, the IP will have the ip address.

If your OS is solaris, then this will not work!

HTH
--ahamed


what's val?

the ping gives somethign like this:
ping "google.com" -c 1

how do you extract the ip from that?

PING google.com (173.194.34.48) 56(84) bytes of data.
64 bytes from par03s03-in-f16.1e100.net (173.194.34.48): icmp_seq=1 ttl=57 time=4.31 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 4.314/4.314/4.314/0.000 ms


what if the url times out

like

ping nonexistentdomaifsffdsdfsdsfn.com
ping: unknown host nonexistentdomaifsffdsdfsdsfn.com

---------- Post updated at 05:10 AM ---------- Previous update was at 05:08 AM ----------

Quote:
Originally Posted by ahamed101
Something like this?
Code:
val=$( ping $url -c 1 )
IP=$(echo $c | awk -F'[()]' '{print $6}')

If ping succeeded, the IP will have the ip address.

If your OS is solaris, then this will not work!

HTH
--ahamed
is the code like this?
val=$( ping $domain -c 1 )
IP=$(echo $val | awk -F'[()]' '{print $6}')
# 7  
Old 12-30-2011
Yes... sorry about the typo...

Code:
val=$( ping $domain -c 1 )
IP=$(echo $val | awk -F'[()]' '{print $6}')

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pinging 5 hosts once every hour

Hello folks; I'm trying to write a shell script to ping 5 hosts i have once every 1 hour and if it receives any failure from any of those hosts, it sends an email alert with the results from this failing ping. Any help would be greatly appreciated (1 Reply)
Discussion started by: Katkota
1 Replies

2. Emergency UNIX and Linux Support

Script for pinging continuously

Hi, I need to set up a script that would write the results of the ping command from one AIX server to another file may be every minute. Like this I need to gather the data for a period of 24 hours. Can someone please help me with this? G (5 Replies)
Discussion started by: ggayathri
5 Replies

3. UNIX Desktop Questions & Answers

Pinging Host

I need to ping websites and I need to see which one has the highest delay. My problem is I need to extract the name Facebook and the time=74.0 ms using awk. I need help doing this please... PING facebook.com (173.252.90.36) 56(84) bytes of data. 64 bytes from... (5 Replies)
Discussion started by: 5sku5
5 Replies

4. IP Networking

Pinging IP located on another interface

Hi, I have a rather strange IP question... Here's my problem: I have a Linux box (call it "turing") with 2 NICs. One network interface (eth0) has an IP assigned, say 192.168.42.50. The other interface (eth1) is up, but has no IP yet. My question: is it possible to determine from... (3 Replies)
Discussion started by: NH2
3 Replies

5. Solaris

Server Pinging Problem

Dear all, I face some problem as below. I have a sun fire 280r server in a network. From that server i am able to ping any system in any network. But i am facing the problem when i try to ping the server from outside netwok. Once i give ping command in the server then only i try to... (1 Reply)
Discussion started by: sudhansu
1 Replies

6. Shell Programming and Scripting

Forking and Pinging

Keep in mind that I haven't done Perl scripting for a LONG time, so I'm quite rusty. This is what I would like to do: - using fork, create 3 or 4 processes to read 3 or 4 different text documents containing server names or IP addresses - in each of those processes, Perl will ping each of those... (7 Replies)
Discussion started by: kooshi
7 Replies

7. Windows & DOS: Issues & Discussions

How to: Linux BOX in Windows Domain (w/out joining the domain)

Dear Expert, i have linux box that is running in the windows domain, BUT did not being a member of the domain. as I am not the System Administrator so I have no control on the server in the network, such as modify dns entry , add the linux box in AD and domain record and so on that relevant. ... (2 Replies)
Discussion started by: regmaster
2 Replies

8. Shell Programming and Scripting

pinging an ip

Hi, How to ping an ip from an unix machine. Can you please let me know the exact command. I used and i got the below error ping 171.18.17.2 bash: ping: command not found Thanks n regards Ammu (1 Reply)
Discussion started by: ammu
1 Replies

9. AIX

pinging IP's in a file

Hey all. I have a long list of IP addresses I want to ping. The IP's are located in a flat file "ping_info.dat". I was wondering what the best way to go about this would be. Can someone help me out? (2 Replies)
Discussion started by: jalge2
2 Replies

10. UNIX for Advanced & Expert Users

Server stopped pinging (in and out)

hi All my Redhat Linux server stopped responding to pings all together. and am also not able to ping out of the box. There are however no issues with internet connectivity and my application is working fine. When I tried to ping another machine (Win98) i could see the pings coming from my... (2 Replies)
Discussion started by: skotapal
2 Replies
Login or Register to Ask a Question