unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Button2: TButton; Memo2: TMemo; Edit1: TEdit; procedure Button1Click(Sender: TObject); function ReturnDWord(IPNo : String): Integer; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var i,x,d:integer; //: integer; S : String; Passed :boolean; MyList :TStringList; NumberList: TStringList; IP,O4,O1,O2,O3 : Integer; begin MyList := TStringList.Create; NumberList := TStringList.Create; //Strip out lines with possible I/P addresses for i := 0 to Memo1.Lines.Count-1 do begin if Pos('[',Memo1.Lines.Strings[i]) > 0 then begin MyList.Add(Memo1.Lines.Strings[i]); end; end; //Strip out I/P possibilities from list for i:= 0 to MyList.Count-1 do begin MyList.Strings[i] := Copy(MyList.Strings[i],Pos('[',MyList.Strings[i])+1,Length(MyList.Strings[i])); MyList.Strings[i] := Copy(MyList.Strings[i],0,Pos(']',MyList.Strings[i])-1); end; //check to see if a dot is present on each line for i:= MyList.Count-1 downto 0 do begin if Pos('.',MyList.Strings[i]) <= 0 then MyList.Delete(i); end; // check to see whether there are 4 dots for i:= MyList.Count-1 downto 0 do begin d := 0; for x:= 1 to Length(MyList.Strings[i]) do begin if MyList.Strings[i][x] = '.' then d:= d+1; end; if d <> 3 then MyList.Delete(i); end; // check to see if the bits between the dots are numerical for i:= 0 to MyList.Count -1 do begin Passed := True; for x:= 1 to Length(MyList.Strings[i]) do begin if MyList.Strings[i][x] in ['0'..'9','.'] then // else Passed := False; end; if Passed = False then MyList.Delete(i); end; // now we know the numbers are all numeric //so we do a range check for i:= MyList.Count-1 downto 0 do begin Passed := True; S := MyList.Strings[i]; x := StrToInt(Copy(S,1,Pos('.',S)-1)); O4 := x; if X > 255 then Passed := False; S := Copy(S,Pos('.',S)+1,Length(S)); x := StrToInt(Copy(S,1,Pos('.',S)-1)); O3 := x; if X > 255 then Passed := False; S := Copy(S,Pos('.',S)+1,Length(S)); x := StrToInt(Copy(S,1,Pos('.',S)-1)); O2 := x; if X > 255 then Passed := False; S := Copy(S,Pos('.',S)+1,Length(S)); X := StrToInt(S); O1:=x; if X > 255 then Passed := False; IP := (O1 + (O2 * 256) + (O3 * 256 *256) + (O4 *256 * 256 *256)); // Now check IP against reserved I/P addresses if (IP >= ReturnDWord('0.0.0.0')) and (IP <= ReturnDWord('0.255.255.255')) then Passed := False; if (IP >= ReturnDWord('10.0.0.0')) and (IP <= ReturnDWord('10.255.255.255')) then Passed := False; if (IP >= ReturnDWord('127.0.0.0')) and (IP <= ReturnDWord('127.255.255.255')) then Passed := False; if (IP >= ReturnDWord('172.16.0.0')) and (IP <= ReturnDWord('172.16.255.255')) then Passed := False; if (IP >= ReturnDWord('192.68.0.0')) and (IP <= ReturnDWord('192.68.255.255')) then Passed := False; if (IP >= ReturnDWord('192.168.0.0')) and (IP <= ReturnDWord('192.168.255.255')) then Passed := False; if (IP >= ReturnDWord('128.0.0.0')) and (IP <= ReturnDWord('128.0.255.255')) then Passed := False; if (IP >= ReturnDWord('223.255.0.0')) and (IP <= ReturnDWord('223.255.255.255')) then Passed := False; if (IP >= ReturnDWord('224.0.0.0')) and (IP <= ReturnDWord('239.0.0.0')) then Passed := False; if (IP >= ReturnDWord('240.0.0.0')) and (IP <= ReturnDWord('255.255.255.254')) then Passed := False; if IP = ReturnDWord('255.255.255.255') then Passed := False; if Passed = False then MyList.Delete(i) else Memo2.Lines.Add(Format('%u', [IP]));//IntToStr(IP));//IntToHex(IP,8)); end; // end; Memo1.Clear; Memo1.Lines.AddStrings(MyList); Memo2.Lines.AddStrings(NumberList); MyList.Free; NumberList.Free; end; function TForm1.ReturnDWord(IPNo : String): Integer; var x,O1,O2,O3,O4,IP :Integer; S:String; begin S := IPNo; x := StrToInt(Copy(S,1,Pos('.',S)-1)); O4 := x; S := Copy(S,Pos('.',S)+1,Length(S)); x := StrToInt(Copy(S,1,Pos('.',S)-1)); O3 := x; S := Copy(S,Pos('.',S)+1,Length(S)); x := StrToInt(Copy(S,1,Pos('.',S)-1)); O2 := x; S := Copy(S,Pos('.',S)+1,Length(S)); X := StrToInt(S); O1:=x; IP := (O1 + (O2 * 256) + (O3 * 256 *256) + (O4 *256 * 256 *256)); ReturnDWord := IP; end; end.