本文整理自网络,侵删。
域名解释为IP
DNS域名解释制作相当简单,原理是将域名解释为IP,函数如下:
function ResolveIP(HostName: string): string; {将域名解释成IP}
type
tAddr = array[0..100] of PInAddr;
pAddr = ^tAddr;
var
I: Integer;
WSA: TWSAData;
PHE: PHostEnt;
P: pAddr;
begin
Result := '';
WSAStartUp($101, WSA);
try
PHE := GetHostByName(pChar(HostName));
if (PHE <> nil) then
begin
P := pAddr(PHE^.h_addr_list);
I := 0;
while (P^[I] <> nil) do
begin
Result := (inet_nToa(P^[I]^));
Inc(I);
end;
end;
except
end;
WSACleanUp;
end;
这个函数必需要Winsock单元支持,Winsock是Windows进行网络通信编程的API接口,所以记得加上
一个木马,你在配置时填入域名,如下
var
dns:phcr='yumato.3322.org';
那当程序开始时就要把yumato.3322.org域名解释为IP,这样木马才会访问得到客户端
建就在程序开始事件放入代码:
Host := ResolveIP(Dns);
Dns变量就是域名,Host变量是得到的IP
Host: string; //IP
Dns: string; //域名
+++++++++++++++++++++++++++++++++++++++++++++++++++++
通过API函数得到操作系统类型
type
TOSVersion = (osUnknown, os95, os95OSR2, os98, os98SE, osNT3, osNT4, os2K, osME, osXP);
function GetOS :TOSVersion;
var
OS :TOSVersionInfo;
begin
ZeroMemory(@OS,SizeOf(OS));
OS.dwOSVersionInfoSize:=SizeOf(OS);
GetVersionEx(OS);
Result:=osUnknown;
if OS.dwPlatformId=VER_PLATFORM_WIN32_NT then begin
case OS.dwMajorVersion of
3: Result:=osNT3;
4: Result:=osNT4;
5: Result:=os2K;
end;
if (OS.dwMajorVersion=5) and (OS.dwMinorVersion=1) then
Result:=osXP;
end else begin
if (OS.dwMajorVersion=4) and (OS.dwMinorVersion=0) then begin
Result:=os95;
if (Trim(OS.szCSDVersion)='B') then
Result:=os95OSR2;
end else
if (OS.dwMajorVersion=4) and (OS.dwMinorVersion=10) then begin
Result:=os98;
if (Trim(OS.szCSDVersion)='A') then
Result:=os98SE;
end else
if (OS.dwMajorVersion=4) and (OS.dwMinorVersion=90) then
Result:=osME;
end;
end;
调用:procedure TForm1.Button1Click(Sender: TObject);
var
os:TosVersion;
osVersion:string;
begin
os:=Getos;
case OS of
os95, os95OSR2: OSVersion:='Windows 95';
os98: OSVersion:='Windows 98';
os98SE: OSVersion:='Windows 98 第二版';
osME: OSVersion:='Windows Millenium Edition';
osNT3, osNT4: OSVersion:='Windows NT';
os2K: OSVersion:='Windows 2000';
osXP: OSVersion:='Windows XP';
end;
showmessage(osversion);
end;
+++++++++++++++++++++++++++++++++++++++++++++++
通过机器名得到IP地址
function nametoip(name:string):string;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
result:='';
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(name));
if HostEnt <> nil then
begin
with HostEnt^ do
result:= Format('%d.%d.%d.%d', [Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
end;
WSACleanup;
end;
通过IP地址得到机器名
function iptoname(ip:string):string;
var
WSAData:TWSAData;
p:PHostEnt;
InetAddr:dword;
begin
WSAStartup(2, WSAData);
InetAddr:= inet_addr(PChar(IP));
try
p:=GetHostByAddr(@InetAddr, Length(IP), PF_Inet);
result:=p^.h_name;
except
result:='';
end;
end;
++++++++++++++++++++++++++++++++++++++++++++++
杀死一个进程
{For Windows 9x/ME/2000/XP }
uses
Tlhelp32;
function KillTask(ExeFileName: string): Integer;
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
Result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(
OpenProcess(PROCESS_TERMINATE,
BOOL(0),
FProcessEntry32.th32ProcessID),
0));
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
++++++++++++++++++++++++++++++++++++++++++++++++
procedure TForm1.Button1Click(Sender: TObject);
begin
KillTask('notepad.exe');
end;
{ For Windows NT/2000/XP }
procedure KillProcess(hWindowHandle: HWND);
var
hprocessID: INTEGER;
processHandle: THandle;
DWResult: DWORD;
begin
SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult);
if isWindow(hWindowHandle) then
begin
// PostMessage(hWindowHandle, WM_QUIT, 0, 0);
{ Get the process identifier for the window}
GetWindowThreadProcessID(hWindowHandle, @hprocessID);
if hprocessID <> 0 then
begin
{ Get the process handle }
processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
False, hprocessID);
if processHandle <> 0 then
begin
{ Terminate the process }
TerminateProcess(processHandle, 0);
CloseHandle(ProcessHandle);
end;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
KillProcess(FindWindow('notepad',nil));
end
相关阅读 >>
Delphi webbrowser选中文本操作 设置webbrowser的内容
Delphi sendtextmessage 等方便的消息发送函数
Delphi 快速获取文件大小(使用_lopen和fileseek,此函数可以快速获取文件大小,即使文件已经被其它程序锁定)
Delphi shellexecute执行cmd命令窗口不关闭
Delphi 莫名奇妙的错误 Delphi is not a valid integer value
更多相关阅读请进入《Delphi》频道 >>