Home > Software engineering >  MFC to write a IP white list program, could you tell me where to start!
MFC to write a IP white list program, could you tell me where to start!

Time:09-24

I am a novice, wrote a client and server, to accept the data,
Want to use the server to send after get IP as white list can access port,
There now, a great god, please help

The client sends code:
 cstrings strIP; 

Cstrings strSource;
Cstrings Address="http://city.ip138.com/ip2city.asp";
CInternetSession session (" Microsoft Internet Browser ", 0);
CHttpFile * myHttpFile=NULL;
MyHttpFile=(CHttpFile *) session. OpenURL (Address);
While (myHttpFile - & gt; ReadString (strSource))
{
Int the begin=0;
The begin=strSource. Find (' [', 0);
If (the begin!=1)
{
Int the end=strSource. Find ('] ');
StrIP=strSource. Mid (begin + 1, end - the begin - 1);


Cstrings szSendText szInfo;
M_ServerIP. GetWindowText (szSendText);
if (! SzSendText. IsEmpty ())
{
SzInfo. The Format (user IP white list, "" % s", strIP);
M_SockClient. Send (szInfo GetBuffer (szInfo GetLength ()), szInfo. GetLength ());
}
}
}


The client code, have access to the user IP, to join white list!

And the service side, I don't know how to write,
Receive the data, how to add the IP protection within the server program!
For example:
Server server running, the server port 80 for sealing state, unless the user run the client after obtaining IP, IP will be sent to the server,
Can access port 80
Is not running the client users can't access, can you tell me the client needs to write!

CodePudding user response:

This thinking is a little trouble
Should not be closed port
Port should have been effective, found that the client to connect the IP check each other, if not in the white list
Closes the connection

CodePudding user response:

The
reference 1/f, CKC response:
this idea a little bit of a problem
Should not be closed port
Port should have been effective, found that the client to connect the IP check each other, if not in the white list
Closes the connection

Probably is this meaning, is there a way to

CodePudding user response:

Why not use the system's own IP filtering strategy?

CodePudding user response:

The
refer to the original poster qq_21961039 response:
I am a novice, wrote a client and server, to accept the data,
Want to use the server to send after get IP as white list can access port,
There now, a great god, please help

The client sends code:
 cstrings strIP; 

Cstrings strSource;
Cstrings Address="http://city.ip138.com/ip2city.asp";
CInternetSession session (" Microsoft Internet Browser ", 0);
CHttpFile * myHttpFile=NULL;
MyHttpFile=(CHttpFile *) session. OpenURL (Address);
While (myHttpFile - & gt; ReadString (strSource))
{
Int the begin=0;
The begin=strSource. Find (' [', 0);
If (the begin!=1)
{
Int the end=strSource. Find ('] ');
StrIP=strSource. Mid (begin + 1, end - the begin - 1);


Cstrings szSendText szInfo;
M_ServerIP. GetWindowText (szSendText);
if (! SzSendText. IsEmpty ())
{
SzInfo. The Format (user IP white list, "" % s", strIP);
M_SockClient. Send (szInfo GetBuffer (szInfo GetLength ()), szInfo. GetLength ());
}
}
}


The client code, have access to the user IP, to join white list!

And the service side, I don't know how to write,
Receive the data, how to add the IP protection within the server program!
For example:
Server server running, the server port 80 for sealing state, unless the user run the client after obtaining IP, IP will be sent to the server,
Can access port 80
Is not running the client users can't access, can you tell me the client needs to write!


Directly on the server with the white list limit line
 
Int the CALLBACK ConnectAcceptCondition (IN LPWSABUF lpCallerId,
IN LPWSABUF lpCallerData,
IN the OUT LPQOS lpSQOS,
IN the OUT LPQOS lpGQOS,
IN LPWSABUF lpCalleeId,
The OUT LPWSABUF lpCalleeData,
The OUT GROUP FAR * g,
IN DWORD dwCallbackData)
{

Sockaddr_in * pCaller=(sockaddr_in *) lpCallerId - & gt; Buf.
Sockaddr_in * pCallee=(sockaddr_in *) lpCalleeId - & gt; Buf.

The IOCPS * pThis=reinterpret_cast & lt; The IOCPS * & gt; (dwCallbackData);

//Do not take connections from ourself.
/* if (pCaller - & gt; Sin_addr. S_un. S_addr==inet_addr (" 127.0.0.1 "))
{
Return CF_REJECT;
}
*/

//
//Do not send an ACK, the attacker Do not know if the server exist or not.
//
If (pThis - & gt; IsInBannedList (pCaller) | | pThis - & gt; IsAlreadyConnected (pCaller))
{
Return CF_REJECT;
}

Return CF_ACCEPT;
}


ClientSocket=WSAAccept (pThis - & gt; M_sockListen,
NULL,
& PThis nLen ConnectAcceptCondition, (DWORD));



CodePudding user response:

The ICMP protocol make a validation
  • Related