#include
#include
#include
#include
#include
#include
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib,"iphlpapi.lib")
#define hostnamelen 256
#define portnamelen 256
#define addresslen hostnamelen+portnamelen
#define flag_all_endpoints 1
#define flag_show_numbers 2
void processandport();
pchar getport(unsigned int port, char* pport)
wsprintfa(pport,"%d",htons((word)port));
return pport;
pchar getip(unsigned int ipaddr, char* pip)
in_addr nipaddr;
nipaddr.s_un.s_addr= ipaddr;
strcpy(pip,inet_ntoa(nipaddr));
return pip;
tchar* processpidtoname(handle hprocesssnap,dword processid,tchar processname[20])
processentry32 processentry;
processentry.dwsize=sizeof(processentry);
lstrcpy(processname,l"..");
if(!process32first(hprocesssnap,&processentry))
while( process32next(hprocesssnap,&processentry));
//printf("")
return processname;
typedef struct d_mib_tcptable_owner_module, *d_pmib_tcptable_owner_module;
typedef struct d_mib_udptable_owner_module, *d_pmib_udptable_owner_module;
static char tcpstate[32] = {
"closed",
"listening",
"syn_sent",
"syn_rcvd",
"established",
"fin_wait1",
"fin_wait2",
"close_wait",
"closing",
"last_ack",
"time_wait",
"delete_tcb"
int main(int argc, char* argv)
processandport();
void processandport()
{int nretcode;
dword i;
wsadata wsadata;
handle hprocesssnap;
d_mib_tcptable_owner_module tcpextable;
d_mib_udptable_owner_module udpextable;
dword udpcount=sizeof(d_mib_tcptable_owner_module);
dword tcpcount=sizeof(d_mib_udptable_owner_module);
tchar szprocessname[max_path];
char szlocalname[hostnamelen], szremotename[hostnamelen];
char szremoteport[portnamelen], szlocalport[portnamelen];
char szlocaladdress[addresslen], szremoteaddress[addresslen];
if( wsastartup(makeword(1, 1), &wsadata ))
//printf("wsastartup error!/n");
return ;
nretcode= getextendedtcptable(&tcpextable,&tcpcount, true,af_inet, tcp_table_owner_module_all, 0);
if( nretcode )
//printf("getextendedtcptable!/n");
return ;
nretcode = getextendedudptable(&udpextable,&udpcount,true,af_inet,udp_table_owner_module,0);
if( nretcode )
//printf("getextendedudptable./n");
return ;
if(hprocesssnap==invalid_handle_value)
//printf("createtoolhelp32snapshot error!/n");
//printf("%-6s%-20s%-20s%-11s%s%-6s/n","協議","本地位址","外部位址", "連線狀態","程序","pid");
for(i=0;iwsprintfa(szlocaladdress,"%s:%s",getip(tcpextable.table[i].dwlocaladdr, szlocalname),getport(tcpextable.table[i].dwlocalport, szlocalport));
wsprintfa(szremoteaddress,"%s:%s",getip(tcpextable.table[i].dwremoteaddr, szremotename),getport(tcpextable.table[i].dwremoteport, szremoteport));
setlocale(lc_all,"chs");
//這裡需要替換
printf("%-6s%-20s%-20s%-11s%ws:%d/n", "tcp",
szlocaladdress, szremoteaddress,tcpstate[tcpextable.table[i].dwstate],processpidtoname(hprocesssnap,tcpextable.table[i].dwowningpid,szprocessname),
tcpextable.table[i].dwowningpid);
for( i = 0; i < udpextable.dwnumentries; i++ )
sprintf( szlocaladdress, "%s:%s",
getip(udpextable.table[i].dwlocaladdr, szlocalname),
getport(udpextable.table[i].dwlocalport, szlocalport));
sprintf( szremoteaddress, "%s", "*:*");
setlocale(lc_all,"chs");
//這裡需要替換
printf("%-6s%-20s%-33s%ws:%d/n", "udp",
szlocaladdress, szremoteaddress,
processpidtoname(hprocesssnap,udpextable.table[i].dwowningpid,szprocessname),
udpextable.table[i].dwowningpid
wsacleanup();
getchar();
return ;
控制台下輸出菱形的作業
這是在控制台下輸出的菱形 using system using system.collections.generic using system.linq using system.text namespace 菱形製作 for z 1 z m z console.write n m 2 else f...
mysql 檢視埠和程序 埠和程序的檢視
netstat命令各個引數說明如下 t 指明顯示tcp埠 u 指明顯示udp埠 l 僅顯示監聽套接字 所謂套接字就是使應用程式能夠讀寫與收發通訊協議 protocol 與資料的程式 p 顯示程序識別符號和程式名稱,每乙個套接字 埠都屬於乙個程式。n 不進行dns輪詢,顯示ip 可以加速操作 即可顯示...
win32控制台下的main
include stdafx.h int main int argc,char argv if strcmp argv 0 1 1.exe 0 if argc 2 strcmp argv 1 0 if argc 2 if argc 2 strcmp argv 1 mzjslt 0 return 0 ...