82315 program c - monitoring sieci

Ukończone Opublikowano May 21, 2011 Płatność przy odbiorze
Ukończone Płatność przy odbiorze

Zadanie polega na zmodyfikowaniu ponizszego programu.

[url removed, login to view] powinien sprawdzac czy dany host jest aktywny na zadanym porcie

[url removed, login to view] powinien byc podawany w kodzie a nie jako argument

[url removed, login to view] powinien pobierac adresy IP z pliku na serwerze. Plik ma format:

192.168.0.1

192.168.0.2

192.168.0.3

192.168.0.n

[url removed, login to view] powinno trwac nie wiecej niz 1sek.(No timeout)

[url removed, login to view] powinien zapisywac aktywne adresy IP w pliku na serwerze.O formacie:

192.168.0.3

192.168.0.8

[url removed, login to view]

192.168.0.n

Dostep do serwera po wygranej aukcji.

===================================================================

#include <sys/socket.h>

#include <sys/time.h>

#include <sys/types.h>

#include <arpa/inet.h>

#include <netinet/in.h>

#include <errno.h>

#include <fcntl.h>

#include <stdio.h>

#include <netdb.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

int main(int argc, char **argv)

{

u_short port; /* user specified port number */

char addr[1023]; /* the address */

struct sockaddr_in address; /* address structures */

struct hostent *host_info; /* host info structure */

short int sock = -1; /* the socket descriptor */

port = atoi(argv[1]);

addr = strncpy(addr, argv[2], 1023);

bzero((char *)&address, sizeof(address)); /* init addr struct */

address.sin_addr.s_addr = inet_addr(addr); /* assign the address */

address.sin_port = htons(port); /* translate int2port num */

/*

* Three simple steps:

* 1. Open the master socket locally

* 2. Try to connect to hostbyport, if it works

* print the successful message.

* 3. If no route then complain with vulgarity

* (it is just a rapid prototype after all)

* Otherwise do nothing.

*/

sock = socket(AF_INET, SOCK_STREAM, 0);

if(connect(sock,(struct sockaddr *)&address,sizeof(address)) == 0)

printf(\"%i is open on %s\\n\", port, argv[2]);

close(sock);

return 0;

}

Android iPad iPhone Mobile App Development

Numer ID Projektu: #5654940

O projekcie

1 oferta Zdalny projekt Aktywny May 22, 2011

Przyznany użytkownikowi:

majorth

A proposal has not yet been provided

zł150 PLN w ciągu 3 dni
(3 ocen)
2.2