unit NMap_Map_Prefixes;
interface
uses
SysUtils, Classes, Types;
type
tNMap_Map_Prefixes =
class(TComponent)
private
{ Private-Deklarationen }
fUrl :
String;
fIncludeFile :
String;
fIncludeUpdate : Boolean;
fDubletten : TStringList;
fHasDubletten : Boolean;
fIncludeCreated : Boolean;
protected
{ Protected-Deklarationen }
procedure SetIncludeUpdate(AValue : Boolean);
function CheckDubletten(sl : TStringList) : Boolean;
function CreateInclude(sl : TStringList) : Boolean;
public
{ Public-Deklarationen }
Constructor Create(aOwner: TComponent);
Override;
Destructor Destroy;
Override;
function GetNameFromMAC(AMac : DWord) :
String;
published
{ Published-Deklarationen }
property Url :
String read fUrl
write fUrl;
property IncludeFile :
String read fIncludeFile
write fIncludeFile;
property IncludeUpdate : Boolean
read fIncludeUpdate
write SetIncludeUpdate;
property Dubletten : TStringList
read fDubletten
write fDubletten;
property HasDubletten : Boolean
read fHasDubletten;
property IncludeCreated : Boolean
read fIncludeCreated;
end;
procedure Register;
implementation
uses
IdHTTP, StrUtils;
procedure Register;
begin
RegisterComponents('
Stephan', [tNMap_Map_Prefixes]);
end;
Constructor tNMap_Map_Prefixes.Create(aOwner: TComponent);
begin
inherited;
fDubletten := TStringList.Create;
fUrl := '
http://linuxnet.ca/ieee/oui/nmap-mac-prefixes';
fIncludeFile := '
NMap_Map_Prefixes.inc';
end;
Destructor tNMap_Map_Prefixes.Destroy;
begin
fDubletten.Free;
inherited;
end;
function MyCompare(List: TStringList; Index1, Index2: Integer): Integer;
begin
Result := CompareText(Copy(List[Index1],8,4096), Copy(List[Index2],8,4096));
end;
function tNMap_Map_Prefixes.GetNameFromMAC(AMac : DWord) :
String;
begin
case AMac
of
$000000 : Result := '
<unbekannt>';
{$I NMap_Map_Prefixes.inc}
else
Result := '
<unbekannt>';
end;
end;
function tNMap_Map_Prefixes.CheckDubletten(sl : TStringList) : Boolean;
var
s :
String;
i : Integer;
begin
fDubletten.Clear;
sl.Sort;
s := '
';
for i := 0
to sl.Count - 1
do begin
if s = Copy(sl[i],1,6)
then begin
fDubletten.Add(Format('
Dublette %s',[Copy(sl[i],1,6)]));
fDubletten.Add(Format('
Dublette %s',[Copy(sl[i - 1],8,4096)]));
fDubletten.Add(Format('
Dublette %s',[Copy(sl[i],8,4096)]));
end;
s := Copy(sl[i],1,6);
end;
Result := fDubletten.Count <> 0;
end;
procedure tNMap_Map_Prefixes.SetIncludeUpdate(AValue : Boolean);
var
idHTTP : TIDHttp;
sl : TStringList;
slInclude : TStringList;
begin
fIncludeUpdate := AValue;
sl := TStringList.Create;
slInclude := TStringList.Create;
idHTTP := tIDHTTP.Create(Self);
sl.Text := idHTTP.Get(fUrl);
fIncludeCreated := CreateInclude(sl);
fHasDubletten := CheckDubletten(sl);
idHTTP.Free;
slInclude.Free;
sl.Free;
fIncludeUpdate := False;
end;
function tNMap_Map_Prefixes.CreateInclude(sl : TStringList) : Boolean;
var
s :
String;
sCase :
String;
i : Integer;
slInclude : TStringList;
begin
DeleteFile(fIncludeFile);
fIncludeCreated := false;
fHasDubletten := false;
slInclude := TStringList.Create;
sl.CustomSort(MyCompare);
s := '
';
sCase := '
';
for i := 0
to sl.Count - 1
do begin
if s <> AnsiReplaceText(Copy(sl[i],8,4096),'
''
','
''
''
')
then begin
if Trim(s) <> '
'
then begin
slInclude.Add(Format('
%s: Result := ''
%s''
;',[sCase,s]));
end;
s := AnsiReplaceText(Copy(sl[i],8,4096),'
''
','
''
''
');
if Trim(s) <> '
'
then begin
sCase := '
$' + Copy(sl[i],1,6);
end;
end else begin
if Length(sCase) = 70
then begin
slInclude.Add(Format('
%s,',[sCase]));
sCase := '
';
end;
if sCase = '
'
then begin
sCase := '
$' + Copy(sl[i],1,6);
end else begin
sCase := sCase + '
, $' + Copy(sl[i],1,6);
end;
end;
end;
slInclude.Add(Format('
%s: Result := ''
%s''
;',[sCase,s]));
slInclude.SaveToFile(fIncludeFile);
slInclude.Free;
Result := FileExists(fIncludeFile);
end;
end.