⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph.c

📁 linux c开发的网络端口检测工具,应用在报警,扫描方面
💻 C
📖 第 1 页 / 共 3 页
字号:
		}	else        SummaryData->Graph = TRUE;    // Plot the points    for(Counter=XOFFSET+1; Counter < XWIDTH; Counter++)                {            if (Count[Counter] > 0)                {                // Convert the bytes/sec to y coords                total[Counter] = (total[Counter]*(YHEIGHT-YOFFSET))/YMax;                tcp[Counter] = (tcp[Counter]*(YHEIGHT-YOFFSET))/YMax;                ftp[Counter] = (ftp[Counter]*(YHEIGHT-YOFFSET))/YMax;                http[Counter] = (http[Counter]*(YHEIGHT-YOFFSET))/YMax;                p2p[Counter] = (p2p[Counter]*(YHEIGHT-YOFFSET))/YMax;                udp[Counter] = (udp[Counter]*(YHEIGHT-YOFFSET))/YMax;                icmp[Counter] = (icmp[Counter]*(YHEIGHT-YOFFSET))/YMax;                total2[Counter] = (total2[Counter]*(YHEIGHT-YOFFSET))/YMax;                tcp2[Counter] = (tcp2[Counter]*(YHEIGHT-YOFFSET))/YMax;                ftp2[Counter] = (ftp2[Counter]*(YHEIGHT-YOFFSET))/YMax;                http2[Counter] = (http2[Counter]*(YHEIGHT-YOFFSET))/YMax;				p2p2[Counter] = (p2p2[Counter]*(YHEIGHT-YOFFSET))/YMax;                udp2[Counter] = (udp2[Counter]*(YHEIGHT-YOFFSET))/YMax;                icmp2[Counter] = (icmp2[Counter]*(YHEIGHT-YOFFSET))/YMax;                // Stack 'em up!                // Total is stacked from the bottom                // Icmp is on the bottom too                // Udp is stacked on top of icmp                udp[Counter] += icmp[Counter];				udp2[Counter] += icmp2[Counter];                // TCP and p2p are stacked on top of Udp                tcp[Counter] += udp[Counter];                tcp2[Counter] += udp2[Counter];                p2p[Counter] += udp[Counter];                p2p2[Counter] += udp2[Counter];				// Http is stacked on top of p2p                http[Counter] += p2p[Counter];                http2[Counter] += p2p2[Counter];				// Ftp is stacked on top of http                ftp[Counter] += http[Counter];                ftp2[Counter] += http2[Counter];                // Plot them!				// Sent                gdImageLine(im, Counter, (YHEIGHT-YOFFSET) - total[Counter], Counter, YHEIGHT-YOFFSET-1, yellow);                gdImageLine(im, Counter, (YHEIGHT-YOFFSET) - icmp[Counter], Counter, YHEIGHT-YOFFSET-1, red);                gdImageLine(im, Counter, (YHEIGHT-YOFFSET) - udp[Counter], Counter, (YHEIGHT-YOFFSET) - icmp[Counter] - 1, brown);                gdImageLine(im, Counter, (YHEIGHT-YOFFSET) - tcp[Counter], Counter, (YHEIGHT-YOFFSET) - udp[Counter] - 1, green);                gdImageLine(im, Counter, (YHEIGHT-YOFFSET) - p2p[Counter], Counter, (YHEIGHT-YOFFSET) - udp[Counter] - 1, purple);                gdImageLine(im, Counter, (YHEIGHT-YOFFSET) - http[Counter], Counter, (YHEIGHT-YOFFSET) - p2p[Counter] - 1, blue);                gdImageLine(im, Counter, (YHEIGHT-YOFFSET) - ftp[Counter], Counter, (YHEIGHT-YOFFSET) - http[Counter] - 1, lblue);												// Receive                gdImageLine(im2, Counter, (YHEIGHT-YOFFSET) - total2[Counter], Counter, YHEIGHT-YOFFSET-1, yellow2);                gdImageLine(im2, Counter, (YHEIGHT-YOFFSET) - icmp2[Counter], Counter, YHEIGHT-YOFFSET-1, red2);                gdImageLine(im2, Counter, (YHEIGHT-YOFFSET) - udp2[Counter], Counter, (YHEIGHT-YOFFSET) - icmp2[Counter] - 1, brown2);                gdImageLine(im2, Counter, (YHEIGHT-YOFFSET) - tcp2[Counter], Counter, (YHEIGHT-YOFFSET) - udp2[Counter] - 1, green2);                gdImageLine(im2, Counter, (YHEIGHT-YOFFSET) - p2p2[Counter], Counter, (YHEIGHT-YOFFSET) - udp2[Counter] - 1, purple2);                gdImageLine(im2, Counter, (YHEIGHT-YOFFSET) - http2[Counter], Counter, (YHEIGHT-YOFFSET) - p2p2[Counter] - 1, blue2);                gdImageLine(im2, Counter, (YHEIGHT-YOFFSET) - ftp2[Counter], Counter, (YHEIGHT-YOFFSET) - http2[Counter] - 1, lblue2);                }            }	if (SentPeak < 1024/8)		snprintf(Buffer2, 50, "Peak Send Rate: %.1f Bits/sec", (double)SentPeak*8);	else if (SentPeak < (1024*1024)/8)		snprintf(Buffer2, 50, "Peak Send Rate: %.1f KBits/sec", ((double)SentPeak*8.0)/1024.0);	else snprintf(Buffer2, 50, "Peak Send Rate: %.1f MBits/sec", ((double)SentPeak*8.0)/(1024.0*1024.0));									if (SummaryData->TotalSent < 1024)		snprintf(Buffer, 30, "Sent %.1f Bytes", (double)SummaryData->TotalSent);						else if (SummaryData->TotalSent < 1024*1024)		snprintf(Buffer, 30, "Sent %.1f KBytes", (double)SummaryData->TotalSent/1024.0);	else snprintf(Buffer, 30, "Sent %.1f MBytes", (double)SummaryData->TotalSent/(1024.0*1024.0));	gdImageString(im, gdFontSmall, XOFFSET+5,  YHEIGHT-20, Buffer, black);	gdImageString(im, gdFontSmall, XWIDTH/2+XOFFSET/2,  YHEIGHT-20, Buffer2, black);					if (ReceivedPeak < 1024/8)       	snprintf(Buffer2, 50, "Peak Receive Rate: %.1f Bits/sec", (double)ReceivedPeak*8);    else if (ReceivedPeak < (1024*1024)/8)    	snprintf(Buffer2, 50, "Peak Receive Rate: %.1f KBits/sec", ((double)ReceivedPeak*8.0)/1024.0);               	else snprintf(Buffer2, 50, "Peak Receive Rate: %.1f MBits/sec", ((double)ReceivedPeak*8.0)/(1024.0*1024.0));    if (SummaryData->TotalReceived < 1024)        snprintf(Buffer, 30, "Received %.1f Bytes", (double)SummaryData->TotalReceived);    else if (SummaryData->TotalReceived < 1024*1024)        snprintf(Buffer, 30, "Received %.1f KBytes", (double)SummaryData->TotalReceived/1024.0);    else snprintf(Buffer, 30, "Received %.1f MBytes", (double)SummaryData->TotalReceived/(1024.0*1024.0));                                                                                                                  gdImageString(im2, gdFontSmall, XOFFSET+5,  YHEIGHT-20, Buffer, black2);                    gdImageString(im2, gdFontSmall, XWIDTH/2+XOFFSET/2,  YHEIGHT-20, Buffer2, black2);    return(YMax);    }void PrepareYAxis(gdImagePtr im, unsigned long long int YMax)    {    char buffer[20];	char YLegend;	long long int Divisor;    int black;    float YTic = 0;    double y;    long int YStep;        black = gdImageColorAllocate(im, 0, 0, 0);    gdImageLine(im, XOFFSET, 0, XOFFSET, YHEIGHT, black);    YLegend = ' ';    Divisor = 1;    if (YMax*8 > 1024*2)        {        Divisor = 1024;    // Display in K        YLegend = 'k';        }    if (YMax*8 > 1024*1024*2)        {        Divisor = 1024*1024; // Display in M        YLegend = 'm';        }    if (YMax*8 > (long long)1024*1024*1024*2)        {        Divisor = 1024*1024*1024; // Display in G        YLegend = 'g';        }    YStep = YMax/10;    if (YStep < 1)        YStep=1;    YTic=YStep;    while (YTic < (YMax - YMax/10))        {        y = (YHEIGHT-YOFFSET)-((YTic*(YHEIGHT-YOFFSET))/YMax);                gdImageLine(im, XOFFSET, y, XWIDTH, y, black);                snprintf(buffer, 20, "%4.1f %cbits/s", (float)(8.0*YTic)/Divisor, YLegend);        gdImageString(im, gdFontSmall, 3, y-7, buffer, black);                YTic += YStep;        }    } void PrepareXAxis(gdImagePtr im, time_t timestamp)    {    char buffer[100];    int black, red;    time_t sample_begin, sample_end;        struct tm *timestruct;    long int MarkTime;	long int MarkTimeStep;    double x;        sample_begin=timestamp-config.range;    sample_end=sample_begin+config.interval;    black = gdImageColorAllocate(im, 0, 0, 0);    red   = gdImageColorAllocate(im, 255, 0, 0);    gdImageLine(im, 0, YHEIGHT-YOFFSET, XWIDTH, YHEIGHT-YOFFSET, black);    // ********************************************************************    // ****  Write the red day/month seperator bars    // ********************************************************************	if ((24*60*60*(XWIDTH-XOFFSET))/config.range > (XWIDTH-XOFFSET)/10)		{		// Day bars	    timestruct = localtime((time_t *)&sample_begin);    	timestruct->tm_sec = 0;	    timestruct->tm_min = 0;    	timestruct->tm_hour = 0;	    MarkTime = mktime(timestruct);                	x = (MarkTime-sample_begin)*( ((double)(XWIDTH-XOFFSET)) / config.range) + XOFFSET;	    while (x < XOFFSET)    	    {        	MarkTime += (24*60*60);	        x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;    	    }	    while (x < (XWIDTH-10))    	    {        	// Day Lines	        gdImageLine(im, x, 0, x, YHEIGHT-YOFFSET, red);    	    gdImageLine(im, x+1, 0, x+1, YHEIGHT-YOFFSET, red);	    	    timestruct = localtime((time_t *)&MarkTime);	        strftime(buffer, 100, "%a, %b %d", timestruct);    	    gdImageString(im, gdFontSmall, x-30,  YHEIGHT-YOFFSET+10, buffer, black);        	        // Calculate Next x    	    MarkTime += (24*60*60);        	x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;	        }		}	else		{    	// Month Bars        timestruct = localtime((time_t *)&sample_begin);        timestruct->tm_sec = 0;        timestruct->tm_min = 0;        timestruct->tm_hour = 0;		timestruct->tm_mday = 1;		timestruct->tm_mon--; // Start the month before the sample        MarkTime = mktime(timestruct);    	x = (MarkTime-sample_begin)*( ((double)(XWIDTH-XOFFSET)) / config.range) + XOFFSET;	    while (x < XOFFSET)    	    {			timestruct->tm_mon++;        	MarkTime = mktime(timestruct);	        x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;    	    }	    while (x < (XWIDTH-10))    	    {        	// Month Lines	        gdImageLine(im, x, 0, x, YHEIGHT-YOFFSET, red);    	    gdImageLine(im, x+1, 0, x+1, YHEIGHT-YOFFSET, red);	    	    timestruct = localtime((time_t *)&MarkTime);	        strftime(buffer, 100, "%b", timestruct);    	    gdImageString(im, gdFontSmall, x-6,  YHEIGHT-YOFFSET+10, buffer, black);        	        // Calculate Next x            timestruct->tm_mon++;            MarkTime = mktime(timestruct);        	x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;	        }						}    // ********************************************************************    // ****  Write the tic marks    // ********************************************************************    timestruct = localtime((time_t *)&sample_begin);    timestruct->tm_sec = 0;    timestruct->tm_min = 0;    timestruct->tm_hour = 0;    MarkTime = mktime(timestruct);	if ((6*60*60*(XWIDTH-XOFFSET))/config.range > 10) // pixels per 6 hours is more than 2		MarkTimeStep = 6*60*60; // Major ticks are 6 hours	else if ((24*60*60*(XWIDTH-XOFFSET))/config.range > 10)		MarkTimeStep = 24*60*60; // Major ticks are 24 hours;	else		return; // Done			x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;	while (x < XOFFSET)   		{		MarkTime += MarkTimeStep;	    x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;    	}    while (x < (XWIDTH-10))    	{	    if (x > XOFFSET) {    		gdImageLine(im, x, YHEIGHT-YOFFSET-5, x, YHEIGHT-YOFFSET+5, black);	       	gdImageLine(im, x+1, YHEIGHT-YOFFSET-5, x+1, YHEIGHT-YOFFSET+5, black);        	}		MarkTime += MarkTimeStep;   		x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;        }    timestruct = localtime((time_t *)&sample_begin);    timestruct->tm_sec = 0;    timestruct->tm_min = 0;    timestruct->tm_hour = 0;    MarkTime = mktime(timestruct);	if ((60*60*(XWIDTH-XOFFSET))/config.range > 2) // pixels per hour is more than 2		MarkTimeStep = 60*60;  // Minor ticks are 1 hour	else if ((6*60*60*(XWIDTH-XOFFSET))/config.range > 2)		MarkTimeStep = 6*60*60; // Minor ticks are 6 hours	else if ((24*60*60*(XWIDTH-XOFFSET))/config.range > 2)		MarkTimeStep = 24*60*60;	else		return; // Done	// Draw Minor Tic Marks	x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;	while (x < XOFFSET)   		{		MarkTime += MarkTimeStep;	    x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;    	}    while (x < (XWIDTH-10))        {	    if (x > XOFFSET) {    		gdImageLine(im, x, YHEIGHT-YOFFSET, x, YHEIGHT-YOFFSET+5, black);        	gdImageLine(im, x+1, YHEIGHT-YOFFSET, x+1, YHEIGHT-YOFFSET+5, black);            }	    MarkTime+=MarkTimeStep;    	x = (MarkTime-sample_begin)*((XWIDTH-XOFFSET)/config.range) + XOFFSET;        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -