请教基础问题如何向指定ip指定端口发送指定好了的数据包

54ruanyan 2004-04-30 06:09:54
如何用C或汇编写一个小程序向指定ip指定端口发送指定好了的数据包
我对编程还是一窍不通呢 谁有空的话帮我解一下惑哎....
最好是完整的代码哎..............
...全文
90 5 点赞 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yueshujiang 2004-04-30
www.pcvc.net
www.vckbase.com
www.vchelp.net
  • 打赏
  • 举报
回复
54ruanyan 2004-04-30
其实就是类似Exploit但要简单的多的东西 只要向指定ip和端口发一个数据包就可以了
winsock编程的基础问题 希望这里有会最基础的winsocks编程的人........
  • 打赏
  • 举报
回复
LuWei103 2004-04-30
2、
UINT CScreenServerDlg::ThreadListen(LPVOID lparam)
{
CScreenServerDlg* pDlg = (CScreenServerDlg *)lparam;
AfxSocketInit();
SOCKET sockServer;
SOCKADDR_IN sockAddrServer;
sockAddrServer.sin_family = AF_INET;
sockAddrServer.sin_port = htons(pDlg->m_nHostPort);
sockAddrServer.sin_addr.s_addr = htonl(INADDR_ANY);

sockServer = ::socket(AF_INET, SOCK_STREAM, NULL);
if (sockServer == INVALID_SOCKET)
return 0;

int iResult = ::bind(sockServer,
(sockaddr *)&sockAddrServer, sizeof(sockAddrServer));
if (iResult == SOCKET_ERROR)
return 0;

iResult = ::listen(sockServer, 5);
if (iResult == SOCKET_ERROR)
return 0;

SOCKET sockClient;
SOCKADDR_IN sockAddrClient;
while (1)
{
int iSizeSockaddr = sizeof(sockaddr);
sockClient = ::accept(sockServer, (sockaddr *)&sockAddrClient,
&iSizeSockaddr);
if (sockClient == INVALID_SOCKET)
continue;
pThreadAccept = ::AfxBeginThread(ThreadAccept,
(LPVOID)sockClient);
if (pThreadAccept == NULL)
continue;

gl_iClientNum++;
CString strTemp;
strTemp.Format("%d", gl_iClientNum);
pDlg->GetDlgItem(IDC_STATIC1)->SetWindowText(_T("愙懕忬懺偺僋儔僀傾儞僩悢: ")+strTemp);
}
return 1;
}

UINT CScreenServerDlg::ThreadAccept(LPVOID lparam)
{
SOCKET sockRecvData;
sockRecvData = (SOCKET)lparam;
while (1)
{
FILEINFO stcFileInfo;
int iResult = ::recv(sockRecvData, (char *)&stcFileInfo, sizeof(FILEINFO), 0);
if (iResult == SOCKET_ERROR || iResult == 0)
{
gl_iClientNum--;
CString strTemp;
strTemp.Format("%d", gl_iClientNum);
AfxGetMainWnd()->GetDlgItem(IDC_STATIC1)->SetWindowText(
_T("愙懕忬懺偺僋儔僀傾儞僩悢: ")+strTemp);
return 0;
}
else
{
CTime tTime = CTime::GetCurrentTime();
int iHour = tTime.GetHour();
int iMinute = tTime.GetMinute();
int iSecond = tTime.GetSecond();
CString temp;
CString name;
temp.Format("%d", iHour);
name = temp;
temp.Format("%d", iMinute);
name += "_" + temp;
temp.Format("%d", iSecond);
name += "_" + temp;
name += ".bmp";
// CString strFileName = SetFileName();
CString strFileName = name;
char* chFileName = new char[250];
strcpy(chFileName, gl_strSavePath+strFileName);
CFile cfRecvFile;
if (!(cfRecvFile.Open(chFileName,
CFile::modeCreate | CFile::modeReadWrite | CFile::typeBinary)))
break;
char* chFileBuf = new char[FILESIZE];
int iRecvNumOne = 0;
int iRecvNumTotal = 0;
int iResult = 0;
for (;;)
{
iRecvNumOne = ::recv(sockRecvData, chFileBuf, FILESIZE, 0);
if (iRecvNumOne == 0 || iRecvNumOne == SOCKET_ERROR)
{
gl_iClientNum--;
CString strTemp;
strTemp.Format("%d", gl_iClientNum);
AfxGetMainWnd()->GetDlgItem(IDC_STATIC1)->SetWindowText(
_T("愙懕忬懺偺僋儔僀傾儞僩悢: ")+strTemp);
delete [] chFileBuf;
return 0;
}
cfRecvFile.Write(chFileBuf, iRecvNumOne);
iRecvNumTotal += iRecvNumOne;
if (iRecvNumTotal >= stcFileInfo.iFileLength)
break;
}
cfRecvFile.Close();
delete [] chFileBuf;
delete [] chFileName;
chFileBuf = "";
chFileName = "";
}
}
return 1;
}
  • 打赏
  • 举报
回复
LuWei103 2004-04-30
1、
SOCKET m_sockClient;
SOCKADDR_IN m_sockAddrServer;


bool CSendFileSocket::InitSocket(const UINT& nServerPort, const LPCTSTR& lpszAddrSock)
{
m_sockClient = ::socket(AF_INET, SOCK_STREAM, 0);
if (m_sockClient == INVALID_SOCKET)
{
return false;
}

unsigned long longAddrSock = inet_addr(lpszAddrSock);
m_sockAddrServer.sin_family = AF_INET;
m_sockAddrServer.sin_port = htons(nServerPort);
memcpy(&m_sockAddrServer.sin_addr, &longAddrSock, sizeof(longAddrSock));

return true;
}

bool CSendFileSocket::ConnectServer()
{
int iResult = ::connect(m_sockClient, (LPSOCKADDR)&m_sockAddrServer, sizeof(m_sockAddrServer));
if (iResult == SOCKET_ERROR)
{
return false;
}

return true;
}
  • 打赏
  • 举报
回复
LuWei103 2004-04-30
需要两个程序,
1、Client
2、Server
  • 打赏
  • 举报
回复
相关推荐
发帖
VC/MFC
加入

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-04-30 06:09
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……