Jump to content

Recommended Posts

Posted

Hello,

 I see TUniServerModule has "BlockedIPList" Property but i don't know how to set value to filter specific ip range.

ex. if i want to allow only IP: 111.222.*.* (ip begin with 111.222) to access my site

how should i have to set in BlockedIPList property ?

 

Thank you

Posted

Hi;

 

You can do it with code in ServerModule Create event

 

Add this

procedure TUniServerModule.UniGUIServerModuleCreate(Sender: TObject);
var
  IPThird,IPFourth: Integer;
  IPThirdString, IPFourthString,IP: string;
begin
  for IPThird := 0 to 255 do
  begin
    IPThirdString := CheckStrLength(inttostr(IPThird));
    for IPFourth := 0 to 255 do
    begin
       IPFourthString := CheckStrLength(inttostr(IPFourth));
       IP := '111.222.'+IPThirdString+'.'+IPFourthString;
       BlockedIPList.Append(IP);
    end;
  end;
end;

and for CheckStrLength function create private function same name in serverModule

 private
    function CheckStrLength(Str:string):string;

and write function

function TUniServerModule.CheckStrLength(Str: string): string;
begin
  if Length(Str)=2 then
    Result := '0'+Str
  else if Length(Str)=1 then
    Result := '00'+Str
  else
    Result := Str;
end;
  • Upvote 2

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...