[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ping



You want a good tool, you'll have to write one :)
maybe the following code will help you out, thought is sends tcp "pings".
it's real "0day" so you might find bugs, but it works.

// TCP Port pinger
// code by rasta

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>

extern int h_errno;
//#include "net.h"

#define PORT 80
#define NUMP 1

resolve(const char *host)
{
 struct hostent *h;
 struct in_addr inp;
 if((inet_aton(host,&inp))==0) {
  if((h=gethostbyname(host))==NULL) {
   herror("gethostbyname");
   exit(1);
  }
  memcpy((void *)&inp.s_addr,(const void *)h->h_addr,h->h_length);
 }
 return (inp.s_addr);
}

int main(int argc, char **argv)
{
 int i, s, port, num, t, *tp;
 struct sockaddr_in sock;
 struct hostent *hostname;

 port=PORT;
 num=NUMP;
 t=1; tp=&t;

 if(argc<2) { 
  printf("usage: %s <host> [num pings] [port]\n",argv[0]); 
  exit(1); }

 if(argc>2) port=atoi(argv[2]);
 if(argc>3) num=atoi(argv[3]);


 sock.sin_family=AF_INET;
 sock.sin_port=htons(port);
 sock.sin_addr.s_addr=resolve(argv[1]);
 bzero((void *)(struct sockaddr *)&sock.sin_zero,8);


 for(i=0;i<num;i++) {
  if(!(s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))) {
   perror("socket"); exit(1); }
  alarm(5);
  if((connect(s,(struct sockaddr *)&sock,sizeof(struct sockaddr_in)))==-1) {
   perror("connect");
   shutdown(s,2);
   close(s);
   exit(1);
  }
  printf("host is up\n");
  shutdown(s,2);
  close(s);
  sleep(1);
 }
 return 0;
}

Noam Meltzer <tsnoam@zahav.net.il> wrote:
> patching the original script sounds much more like what i need if i 
> don't find something else.
> on the first look  it might seem like  ping -s on solaris is much better 
> than the default ping but thats not always the case.
> lets assume that you need to get statistics on the status of the 
> network. statistics like, the host is up or down, just that no more than 
> that. what ping in solaris does is sending packets to a host until it 
> responds or until (i'm not sure) a certain time has been exceeded or X 
> packets didn't return. if one packet returns it's enough. in such cases 
> the solaris' ping is much more usefull and comfortable to use.
> 
> 
> guy keren wrote:
> 
> > On Thu, 31 May 2001, Noam Meltzer wrote:
> > 
> >> Well guys thank you all... but that what i really didn't want... sctipts
> >> i can write my self.
> >> What i really wanted is to find out if you can get what the ping binary
> >> in solaris does not a scripts to emulate it.
> >> Is there such a tool for linux?
> > 
> > 
> > a script _is_ a tool. what is the problem iwth writing this script and
> > installing it somewhere on the system? if yo want, you can turn this into
> > a one-line perl script given to perl on the command line.
> > 
> > there is no difference between that and a binary program. btw, the way
> > 'ping' behaves on linux by edfault is more useful then the way it does on
> > solaris (i.e. 'host is alive'? that's much less useful then what 'ping -s'
> > gives you on solaris).
> > 
> > btw, why do _you_ think the output on solaris is better then on linux? for
> > customer support via the phone? then tel the user to type 'ping -c 1' and
> > read the output to you.
> > 
> > --
> > guy
> > 
> > "For world domination - press 1,
> >  or dial 0, and please hold, for the creator." -- nob o. dy
> > 
> > 
> > =================================================================
> > To unsubscribe, send mail to linux-il-request@linux.org.il with
> > the word "unsubscribe" in the message body, e.g., run the command
> > echo unsubscribe | mail linux-il-request@linux.org.il
> > 
> > 
> > 
> 

-- 
http://www.rshell.org
Join #shellcode on EFnet.
rasta@rshell.org

=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il