18,356
社区成员
发帖
与我相关
我的任务
分享
CString strIP;
CString strSource;
CString Address = "http://city.ip138.com/ip2city.asp";
CInternetSession session("Microsoft Internet Browser", 0);
CHttpFile *myHttpFile = NULL;
myHttpFile = (CHttpFile *)session.OpenURL(Address);
while(myHttpFile->ReadString(strSource))
{
int begin = 0;
begin = strSource.Find('[', 0);
if(begin != -1)
{
int end = strSource.Find(']');
strIP = strSource.Mid(begin+1, end-begin-1);
CString szSendText, szInfo;
m_ServerIP.GetWindowText(szSendText);
if (!szSendText.IsEmpty())
{
szInfo.Format("[白名单]用户IP: %s",strIP);
m_SockClient.Send(szInfo.GetBuffer(szInfo.GetLength()), szInfo.GetLength());
}
}
}
int CALLBACK ConnectAcceptCondition(IN LPWSABUF lpCallerId,
IN LPWSABUF lpCallerData,
IN OUT LPQOS lpSQOS,
IN OUT LPQOS lpGQOS,
IN LPWSABUF lpCalleeId,
OUT LPWSABUF lpCalleeData,
OUT GROUP FAR *g,
IN DWORD dwCallbackData)
{
sockaddr_in* pCaller=(sockaddr_in*)lpCallerId->buf;
sockaddr_in* pCallee=(sockaddr_in*)lpCalleeId->buf;
IOCPS* pThis = reinterpret_cast<IOCPS*>(dwCallbackData);
// Do not take connections from ourself.
/* if ( pCaller->sin_addr.S_un.S_addr == inet_addr("127.0.0.1") )
{
return CF_REJECT;
}
*/
//
// Do not send ACK, the attacker do not know if the server exist or not.
//
if ( pThis->IsInBannedList(pCaller) || pThis->IsAlreadyConnected(pCaller) )
{
return CF_REJECT;
}
return CF_ACCEPT;
}
clientSocket = WSAAccept(pThis->m_sockListen,
NULL,
&nLen,ConnectAcceptCondition,(DWORD)pThis);