Jump to content

Allow Only IP Range


carrera

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...