#include
#include
#include
#include
#include
#include
using namespace std;
#define MST (-7)
int main(int argc, char *argv[])
{
if(argc != 2)
{
printf("usage: %s
exit(1);
}
hostent * record = gethostbyname(argv[1]);
if(record == NULL)
{
printf("%s is unavailable\n", argv[1]);
exit(1);
}
in_addr * address = (in_addr * )record->h_addr;
string ip_address = inet_ntoa(* address);
// get the current time
time_t rawtime;
tm * ptm;
time ( &rawtime );
ptm = gmtime ( &rawtime );
cout << argv[1] << " (" << ip_address << ")\n";
// log this information to ipaddr.log
ofstream ipaddr_log("ipaddr.log", ios::app);
ipaddr_log << (ptm->tm_hour+MST%24) << ":" << (ptm->tm_min) << " " << argv[1] << " (" << ip_address << ")" << endl;
ipaddr_log.close();
return 0;
}