Kill TCP Connection源代码
来源:互联网 发布:淘宝云客服是干什么的 编辑:程序博客网 时间:2024/06/05 00:43
//**********************************************************************
// Version: V1.0
// Coder: WinEggDrop
// Date Release: NULL
// Purpose: Kill An Active TCP Connection
// Test PlatForm: Win 2K Pro And Server SP4
// Compiled On: LCC 3.0,May Compile On VC++ 6.0(Not Test Yet)
//**********************************************************************
#include <winsock.h>
#include <windows.h>
#include <stdio.h>
#include <iphlpapi.h>
// Function ProtoType Declaration
//---------------------------------------------------------------------------------------------------------------------------
BOOL KillTCPConnection(const char *LocalAddress,const char *LocalPort,const char *RemoteAddress,const char *RemotePort);
BOOL IsDigits(const char *String);
void Usage(const char *Command);
//---------------------------------------------------------------------------------------------------------------------------
// End Of Fucntion ProtoType Declaration
// Main Function
int main(int argc,char *argv[])
{
if (argc!=5) // There Are Not 5 Arguement In Total
{
Usage(argv[0]); // Display The Usage
return -1; // Quit The Program
}
KillTCPConnection(argv[1],argv[2],argv[3],argv[4]); // Kill The TCP Connection
return 0; // Quit The Program
}// End Of Main Function
//-------------------------------------------------------------------------
// Purpose: To Display The Usage Of The Program
// Return Type: Void
// Parameters: Const Char *Command
//-------------------------------------------------------------------------
void Usage(const char *Command)
{
printf("/r/nUsage: %s LocalAddress LocalPort RemoteAddress,RemotePort/r/n",Command); // Display The Usage
printf("Example: %s 192.168.0.1 1234 12.12.12.12 22222/r/n",Command); // Display A Example
}// End Of Usage Function
//-------------------------------------------------------------------------
// Purpose: To Check Whether The String Is Really A Number
// Return Type: Boolean
// Parameters: Const Char *String
//-------------------------------------------------------------------------
BOOL IsDigits(const char *String)
{
int StringLength = strlen(String); // Get The Length Of The String
for (int i = 0;i < StringLength;i++) // Check Every Character Of The String
{
if (String[i] < 48 || String[i] > 57) // The Character Is Not A Digit
{
return FALSE; // Return False
}
}
return TRUE; // Return True As All Characters Are Digits
}// End Of IsDigits Function
//--------------------------------------------------------------------------------------------
// Purpose: To Kill An Active TCP Connection
// Return Type: Boolean
// Parameters:
// 1.Const Char *LocalAddress --> The Local Address Of The TCP Connection
// 2.Const Char *LocalPort --> The Local Port Of The TCP Connection
// 3.Const Char *RemoteAddress --> The Remote Address Of The TCP Connection
// 4.Const Char *RemotePort --> The Remote Port Of The TCP Connection
//--------------------------------------------------------------------------------------------
BOOL KillTCPConnection(const char *LocalAddress,const char *LocalPort,const char *RemoteAddress,const char *RemotePort)
{
MIB_TCPROW TcpRow; // Declare A TCP Raw
if (!IsDigits(LocalPort)) // The Local Port Is Not A Number
{
printf("Invalid Local Port/r/n"); // Display Error Message
return FALSE; // Return False
}
if (atoi(LocalPort) < 0 || atoi(LocalPort) > 65535) // The Local Port Is Out Of Bound
{
printf("Local Port Out Of Bound/r/n"); // Display Error Message
return FALSE; // Return False
}
if (!IsDigits(RemotePort)) // The Remote Port Is Not A Number
{
printf("Invalid Remote Port/r/n"); // Display Error Message
return FALSE; // Return False
}
if (atoi(RemotePort) < 0 || atoi(RemotePort) > 65535) // The Remote Port Is Out Of Bound
{
printf("Remote Port Out Of Bound/r/n"); // Display Error Message
return FALSE; // Return False
}
// Set The TCP Row Entry
TcpRow.dwLocalPort = htons(atoi(LocalPort));
TcpRow.dwRemotePort = htons(atoi(RemotePort));
TcpRow.dwLocalAddr = inet_addr(LocalAddress);
TcpRow.dwRemoteAddr = inet_addr(RemoteAddress);
TcpRow.dwState = MIB_TCP_STATE_DELETE_TCB; // Flag To Indicate The System To End That TCP Connection
if (SetTcpEntry(&TcpRow) == NO_ERROR) // Call The API With No Error
{
printf("Delete The TCP Connection %s:%s-->%s:%s Successfully/r/n",LocalAddress,LocalPort,RemoteAddress,RemotePort); // Display Successful Message
return TRUE; // Return True
}
// Some Error Must Be Occurred
printf("Fail To Delete The TCP Connection Error Code:%d/r/n",GetLastError()); // Display The Error Code
return FALSE; // Return False
}// End Of KillTCPConnection Function
// End Of File
// Version: V1.0
// Coder: WinEggDrop
// Date Release: NULL
// Purpose: Kill An Active TCP Connection
// Test PlatForm: Win 2K Pro And Server SP4
// Compiled On: LCC 3.0,May Compile On VC++ 6.0(Not Test Yet)
//**********************************************************************
#include <winsock.h>
#include <windows.h>
#include <stdio.h>
#include <iphlpapi.h>
// Function ProtoType Declaration
//---------------------------------------------------------------------------------------------------------------------------
BOOL KillTCPConnection(const char *LocalAddress,const char *LocalPort,const char *RemoteAddress,const char *RemotePort);
BOOL IsDigits(const char *String);
void Usage(const char *Command);
//---------------------------------------------------------------------------------------------------------------------------
// End Of Fucntion ProtoType Declaration
// Main Function
int main(int argc,char *argv[])
{
if (argc!=5) // There Are Not 5 Arguement In Total
{
Usage(argv[0]); // Display The Usage
return -1; // Quit The Program
}
KillTCPConnection(argv[1],argv[2],argv[3],argv[4]); // Kill The TCP Connection
return 0; // Quit The Program
}// End Of Main Function
//-------------------------------------------------------------------------
// Purpose: To Display The Usage Of The Program
// Return Type: Void
// Parameters: Const Char *Command
//-------------------------------------------------------------------------
void Usage(const char *Command)
{
printf("/r/nUsage: %s LocalAddress LocalPort RemoteAddress,RemotePort/r/n",Command); // Display The Usage
printf("Example: %s 192.168.0.1 1234 12.12.12.12 22222/r/n",Command); // Display A Example
}// End Of Usage Function
//-------------------------------------------------------------------------
// Purpose: To Check Whether The String Is Really A Number
// Return Type: Boolean
// Parameters: Const Char *String
//-------------------------------------------------------------------------
BOOL IsDigits(const char *String)
{
int StringLength = strlen(String); // Get The Length Of The String
for (int i = 0;i < StringLength;i++) // Check Every Character Of The String
{
if (String[i] < 48 || String[i] > 57) // The Character Is Not A Digit
{
return FALSE; // Return False
}
}
return TRUE; // Return True As All Characters Are Digits
}// End Of IsDigits Function
//--------------------------------------------------------------------------------------------
// Purpose: To Kill An Active TCP Connection
// Return Type: Boolean
// Parameters:
// 1.Const Char *LocalAddress --> The Local Address Of The TCP Connection
// 2.Const Char *LocalPort --> The Local Port Of The TCP Connection
// 3.Const Char *RemoteAddress --> The Remote Address Of The TCP Connection
// 4.Const Char *RemotePort --> The Remote Port Of The TCP Connection
//--------------------------------------------------------------------------------------------
BOOL KillTCPConnection(const char *LocalAddress,const char *LocalPort,const char *RemoteAddress,const char *RemotePort)
{
MIB_TCPROW TcpRow; // Declare A TCP Raw
if (!IsDigits(LocalPort)) // The Local Port Is Not A Number
{
printf("Invalid Local Port/r/n"); // Display Error Message
return FALSE; // Return False
}
if (atoi(LocalPort) < 0 || atoi(LocalPort) > 65535) // The Local Port Is Out Of Bound
{
printf("Local Port Out Of Bound/r/n"); // Display Error Message
return FALSE; // Return False
}
if (!IsDigits(RemotePort)) // The Remote Port Is Not A Number
{
printf("Invalid Remote Port/r/n"); // Display Error Message
return FALSE; // Return False
}
if (atoi(RemotePort) < 0 || atoi(RemotePort) > 65535) // The Remote Port Is Out Of Bound
{
printf("Remote Port Out Of Bound/r/n"); // Display Error Message
return FALSE; // Return False
}
// Set The TCP Row Entry
TcpRow.dwLocalPort = htons(atoi(LocalPort));
TcpRow.dwRemotePort = htons(atoi(RemotePort));
TcpRow.dwLocalAddr = inet_addr(LocalAddress);
TcpRow.dwRemoteAddr = inet_addr(RemoteAddress);
TcpRow.dwState = MIB_TCP_STATE_DELETE_TCB; // Flag To Indicate The System To End That TCP Connection
if (SetTcpEntry(&TcpRow) == NO_ERROR) // Call The API With No Error
{
printf("Delete The TCP Connection %s:%s-->%s:%s Successfully/r/n",LocalAddress,LocalPort,RemoteAddress,RemotePort); // Display Successful Message
return TRUE; // Return True
}
// Some Error Must Be Occurred
printf("Fail To Delete The TCP Connection Error Code:%d/r/n",GetLastError()); // Display The Error Code
return FALSE; // Return False
}// End Of KillTCPConnection Function
// End Of File
- Kill TCP Connection源代码
- use tcp kill to kill the tcp connection
- Kill a postgresql session/connection
- TCP Connection Established! ^_^
- TCP Connection Termination
- TCP Connection Termination
- 6.5 TCP Connection Repair
- TCP closing a connection
- Nginx源代码分析-connection处理
- A sample for TCP connection
- How TCP Establishes A Connection
- Connection Establishment in TCP 2
- TCP: terminating a connection 3
- tcp connection setup的实现
- 3-way TCP connection establishment
- TCP 偶尔出现connection refused
- TCP 连接状态图 (TCP Connection State Diagram)
- TCP 连接状态图 (TCP Connection State Diagram)
- 【转】东方通:SOA 上的成功案例
- 【转】你的SOA团队不应该说的七件事
- 一位浙江大学教授让人发冷汗的讲演
- 【转】研究 SOA 中信息管理的不同方法
- j2me 的中文网络传输的处理
- Kill TCP Connection源代码
- 怎样卸载IE 5.0 和 IE 6.0
- 查看应用端口:精准Kill进程
- 神经网络BP算法(C程序实现)
- 高中成绩管理程序又升级了
- C# 关机源代码
- 链表插入与删除操作中的头、尾指针
- Win2003 SP0/SP1 下安装WMP11
- omni的 osx86 ati 驱动