I implemented a simple IP address banning system in one of my Web Services.
In the Web Services code, this is what I had to do.
var WebModule: TWebModule; Request: TWebRequest; TempIP, IP: string; IPNetwork: TIdNetworkCalculator; Banned1, Banned2: Boolean;begin WebModule := GetSOAPWebModule; Request := WebModule.Request; IP := Request.GetFieldByName('HTTP_X_FORWARDED_FOR'); if IP = '' then IP := Request.RemoteAddr; IPNetwork := TIdNetworkCalculator.Create(nil); try while Length(IP)>0 do begin TempIP := Fetch(IP, ', '); IPNetwork.NetworkAddress.AsString := '202.12.94.0'; IPNetwork.NetworkMaskLength := 23; Banned1 := IPNetwork.IsAddressInNetwork(TempIP);
IPNetwork.NetworkAddress.AsString := '172.16.0.0'; IPNetwork.NetworkMaskLength := 12; Banned2 := IPNetwork.IsAddressInNetwork(TempIP); if Banned1 or Banned2 then raise ERemotableException.Create('Your domain address is banned.'); end; finally IPNetwork.Free; end;end;
In 2017, with the release of Delphi 10.2 Tokyo, Embarcadero introduced a specialized implementation of the Observer pattern into the System.Classes unit. While it has been in the wild for 9 years, it remains a "hidden" architecture for many, primarily because it serves as the invisible engine behind LiveBindings. Other than live bindings, you can also use the Observer pattern as a way to update component settings to the Windows registry, an .ini file, or persist it elsewhere.
System.Classes