locateip.c
资源名称:itunnet.rar [点击查看]
上传用户:lylmjq
上传日期:2020-10-14
资源大小:4k
文件大小:2k
源码类别:
弱点检测代码
开发平台:
C/C++
- /* Programme Locateip
- Objet : Determine &IP , date de connection
- Auteur JY.TORRES
- Date 26 Fevrier 2008*/
- #include <sys/types.h>
- #include <utmp.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- main ()
- {
- struct utmp *entry;
- struct utmp id;
- time_t uttime;
- struct tm *ts;
- char buf[80];
- unsigned int ipaddr;
- unsigned short ureserved;
- char type[20];
- strcpy(id.ut_line,ttyname(0)+ 5);
- entry = getutline( &id );
- ipaddr = entry->ut_addr;
- uttime = entry->ut_time;
- ureserved = entry->ut_reserved1;
- if(*(entry->ut_host) == ' ')
- printf ("tty %s est connecte a un MUX n");
- else {
- printf("/dev/%s ",entry->ut_line);
- printf("from host %s (IP #0x%x = %d.%d.%d.%d) n",
- entry->ut_host,
- ipaddr,
- (ipaddr >> 24 ) & 255,
- (ipaddr >> 16 ) & 255,
- (ipaddr >> 8 ) & 255,
- (ipaddr ) & 255);
- switch (entry->ut_type) {
- case 0 : strcpy(type , "EMPTY");
- break;
- case 1 : strcpy(type , "RUN_LVL");
- break;
- case 2 : strcpy(type , "BOOT_T E");
- break;
- case 3 : strcpy(type , "OLD_TIME");
- break;
- case 4 : strcpy(type , "NEW_TIME");
- break;
- case 5 : strcpy(type , "INIT_PROCESS");
- break;
- case 6 : strcpy(type , "LOGIN_PROCESS");
- break;
- case 7 : strcpy(type , "USER_PROCESS");
- break;
- case 8 : strcpy(type , "DEAD_PROCESS");
- break;
- case 9 : strcpy(type , "ACCOUNTING");
- break;
- default : strcpy(type , "UTMAXTYPE");
- break;
- }
- printf(" User : %s de type %s au process %d n",
- entry->ut_user,
- type ,
- entry->ut_pid );
- time(&entry->ut_time) ;
- ts = localtime(&entry->ut_time);
- strftime(buf, sizeof(buf), " Arrive : %a %Y-%m-%d %H:%M:%S %Z", ts) ;
- puts(buf);
- }
- }