Date: Sun, 14 Jan 2007 16:24:51 +0100 From: "Pietro Cerutti" <pietro.cerutti@gmail.com> To: "Grant Peel" <gpeel@thenetnow.com> Cc: freebsd-questions@freebsd.org Subject: Re: Identifying a Remote Machine. Message-ID: <e572718c0701140724j7ade3d01u86229e3e553967d0@mail.gmail.com> In-Reply-To: <008f01c737e9$c5518470$6501a8c0@GRANT> References: <007e01c737d7$20573170$6501a8c0@GRANT> <e572718c0701140621m39011e2cjdd2424cf07038fc@mail.gmail.com> <008f01c737e9$c5518470$6501a8c0@GRANT>
next in thread | previous in thread | raw e-mail | index | archive | help
On 1/14/07, Grant Peel <gpeel@thenetnow.com> wrote: > ACtually no, > > Sory if the question was vauge, > > What I am looking to do is to create a tool that will identify what MACHINE > (not domain) an ip is being used on. Check out this: #include <netinet/in.h> #include <sys/types.h> #include <sys/socket.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <strings.h> #define MAX_BUFF 128 #define MAX_NAME 128 int main(int argc, char **argv) { char buf[MAX_BUFF], name[MAX_NAME]; int recv, sock, addrlen; struct sockaddr_in addr, from; if(argc != 3) { fprintf(stderr, "usage: %s ip port\n", argv[0]); return(1); } addrlen = sizeof(struct sockaddr); /* get hostname */ bzero(&name, MAX_NAME); if(gethostname(name, MAX_NAME) == -1) { perror("gethostname"); return(1); } /* create socket */ if((sock = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { perror("socket"); return(1); } /* create addres */ bzero(&addr, addrlen); addr.sin_family = AF_INET; addr.sin_port = htons((int)strtol(argv[2], (char **)NULL, 10)); if(inet_aton(argv[1], addr.sin_addr) == 0) { perror("inet_aton"); return(1); } /* bind */ if(bind(sock, (struct sockaddr *)&addr, addrlen) == -1) { perror("bind"); return(1); } /* loop infinitely */ for(;;) { /* receive */ if((recv = recvfrom(sock, buf, MAX_BUFF -1, 0, (struct sockaddr *)&from, &addrlen)) == -1) { perror("recvfrom"); continue; } buf[recv] = '\0'; /* send hostname */ if(sendto(sock, name, MAX_NAME, 0, (struct sockaddr *)&from, sizeof(struct sockaddr)) == -1) { perror("sendto"); continue; } } return(0); } > > -Grant > > ----- Original Message ----- > From: "Pietro Cerutti" <pietro.cerutti@gmail.com> > To: "Grant Peel" <gpeel@thenetnow.com> > Cc: <freebsd-questions@freebsd.org> > Sent: Sunday, January 14, 2007 9:21 AM > Subject: Re: Identifying a Remote Machine. > > > > On 1/14/07, Grant Peel <gpeel@thenetnow.com> wrote: > >> Hi all, > > Hello, > > > >> The only reply I need from the server is the hostname. That will tell ne > >> that the IP is live and what machine its on. > > > > Wouldn't a ping be enough if you just need to know whether the machine is > > on? > > > >> > >> -Grant > > > > > > -- > > Pietro Cerutti > > ICQ: 117293691 > > PGP: 0x9571F78E > > > > - ASCII Ribbon Campaign - > > against HTML e-mail and > > proprietary attachments > > www.asciiribbon.org > > > > > > > -- Pietro Cerutti ICQ: 117293691 PGP: 0x9571F78E - ASCII Ribbon Campaign - against HTML e-mail and proprietary attachments www.asciiribbon.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e572718c0701140724j7ade3d01u86229e3e553967d0>