建个DLL的工程,就可以使用以下代码啦...
大部份都是我从CSDN抄来的...忘记都是谁的代码了,总之不是我写的.library NetTool;uses
SysUtils,
Windows,
Classes,
db,
graphics,
jpeg,
Winsock,
NMUDP,
dm in 'dm.pas' {DM1: TDataModule};type
IPAddr = Cardinal;
PSendARP=function (const DestIP, SrcIP: IPAddr;PMacAddr :PULong; var PhyAddrLen: ULong):dword;stdcall;
{$R *.res}function amchange(pas:pchar):pchar;stdcall; //加密
var
s1,s2:String;
i:Integer;
j,k:byte;
begin
s2:='';
s1:=pas;
repeat
Randomize;
j:=random(15);
until j>0;
For i:=1 to length(s1) Do
begin
k:=ord(s1[i]);
asm
mov dl,k
mov dh,j
xor dl,dh
mov k,dl
end;
s1[i]:=chr(k);
end;
s2:=s1+inttostr(j);
if j<=9 then s2:=s2+'1';
if j>9 then s2:=s2+'2';
amchange:=pchar(s2);
end;function bmchange(pas:pchar;pasb:pchar):integer;stdcall; //解密
var
s1,s2,s3:String;
i:Integer;
j,k:byte;
begin
try
s1:=pas;
if strtoint(s1[length(s1)])=1 then
begin
j:=strtoint(s1[length(s1)-1]);
delete(s1,length(s1)-1,2);
end
else begin
j:=strtoint(s1[length(s1)-2]+s1[length(s1)-1]);
delete(s1,length(s1)-2,3);
end;
For i:=1 to length(s1) Do
begin
k:=ord(s1[i]);
asm
mov dl,k
mov dh,j
xor dl,dh
mov k,dl
end;
s1[i]:=chr(k);
end;
s2:=s1;
//**********************************
s1:=pasb;
if strtoint(s1[length(s1)])=1 then
begin
j:=strtoint(s1[length(s1)-1]);
delete(s1,length(s1)-1,2);
end
else begin
j:=strtoint(s1[length(s1)-2]+s1[length(s1)-1]);
delete(s1,length(s1)-2,3);
end;
For i:=1 to length(s1) Do
begin
k:=ord(s1[i]);
asm
mov dl,k
mov dh,j
xor dl,dh
mov k,dl
end;
s1[i]:=chr(k);
end;
s3:=s1;
except
s2:='a';
s3:='b';
end;
//************************
if trim(s2)=trim(s3) then
bmchange:=0
else
bmchange:=-1;
end;function imgr(server,database,user,password,path:pchar;number:integer):integer;stdcall; //存取图像
var
dm1:TDM1;
begin
try
dm1:=TDM1.Create(nil);
dm1.ADOC1.ConnectionString:='Provider=SQLOLEDB.1;Password='+trim(password)+';Persist Security Info=True;User ID='+trim(user)+';Initial Catalog='+trim(database)+';Data Source='+trim(server)+';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;';
dm1.ADOC1.Connected:=true;
dm1.ADOQuery1.Close;
dm1.ADOQuery1.SQL.Clear;
dm1.ADOQuery1.SQL.Add('select ft from st where xh=:a');
dm1.ADOQuery1.Parameters.ParamValues['a']:=number;
dm1.ADOQuery1.Open;
dm1.ADOQuery1Ft.SaveToFile(trim(path));
imgr:=0;
except
imgr:=-1;
end;
dm1.ADOQuery1.Close;
dm1.ADOC1.Connected:=false;
end;function imgw(server,database,user,password,path:pchar;number:integer):integer;stdcall;
var
dm1:TDM1;
jp:TJPEGImage;
bm:Tbitmap;
Stream:TMemoryStream;
filee,filename:string;
begin
try
dm1:=TDM1.Create(nil);
bm:=Tbitmap.Create;
jp:=TJPEGImage.Create;
stream:=TMemoryStream.Create;
filename:=path;
filee:=copy(filename,length(filename)-2,3);
if filee='jpg' then
begin
jp.LoadFromFile(path);
end
else begin
bm.LoadFromFile(path);
jp.Assign(bm);
end;
jp.SaveToStream(stream);
dm1.ADOC1.ConnectionString:='Provider=SQLOLEDB.1;Password='+trim(password)+';Persist Security Info=True;User ID='+trim(user)+';Initial Catalog='+trim(database)+';Data Source='+trim(server)+';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;';
dm1.ADOC1.Connected:=true;
dm1.ADOQuery1.Close;
dm1.ADOQuery1.SQL.Clear;
dm1.ADOQuery1.SQL.Add('update st set ft=:b where xh=:a');
dm1.ADOQuery1.Parameters.ParamValues['a']:=number;
dm1.adoquery1.Parameters.ParamByName('b').LoadFromStream(stream,ftBlob);
dm1.ADOQuery1.ExecSQL;
stream.Free;
bm.Free;
jp.Free;
imgw:=0;
except
imgw:=-1;
end;
dm1.ADOQuery1.Close;
dm1.ADOC1.Connected:=false;
end;function pron(mac:pchar):integer;stdcall;
var
NMUDP1: TNMUDP;
s:string;
i:array[1..6] of byte;
cb:array[1..6] of char;
c:array[1..102] of char;
j,j1,ne:integer;
begin
NMUDP1:=TNMUDP.Create(nil);
s:=mac;
if length(s)<>12 then
begin
pron:=-1;
exit;
end;
i[1]:=strtoint('$'+copy(s,1,2));
i[2]:=strtoint('$'+copy(s,3,2));
i[3]:=strtoint('$'+copy(s,5,2));
i[4]:=strtoint('$'+copy(s,7,2));
i[5]:=strtoint('$'+copy(s,9,2));
i[6]:=strtoint('$'+copy(s,11,2));
for j:=1 to 6 do
begin
c[j]:=chr(255);
end;
for j:=1 to 6 do
begin
cb[j]:=chr(i[j]);
end;
ne:=0;
for j:=1 to 16 do
begin
ne:=ne+6;
for j1:=1 to 6 do
begin
c[j1+ne]:=cb[j1];
end;
end;
nmudp1.SendBuffer(c,102);
pron:=0;
end;function getip():pchar;stdcall;
var
ch:array[1..32] of Char;
i:Integer;
ip,ipstr:string;
WSData:TWSAData;
MyHost:PHostEnt;
begin
if WSAstartup(2,wsdata)<>0 then
begin
Result:='-1';
exit;
end;
if getHostName(@ch[1],32)<>0 then
begin
Result:='-1';
exit;
end;
MyHost:=GetHostByName(@ch[1]);
if MyHost=nil then
begin
Result:='-1';
exit;
end;
for i:=1 to 4 do
begin
ip:=inttostr(Ord(MyHost.h_addr^[i-1]));
ipstr:=ipstr+ip;
if i<4 then ipstr:=ipstr+'.';
end;
result:=pchar(ipstr);
end;function getmac():pchar;stdcall;
label Fend;
var
DestIP:IPAddr;
pMacAddr: PULong;
AddrLen: ULong;
MacAddr: array[0..5] of byte;
p: PByte;
s,ipstr: string;
i: integer;
SendARP:PSendARP;
HM:Thandle;
begin
ipstr:=getip();
if trim(ipstr)='' then
begin
Result:='-1';
exit;
end;
Result:='-1';
hm := loadlibrary('iphlpapi.dll');
if hm = 0 then goto Fend;
SendARP := getprocaddress(hm, 'SendARP');
if @SendARP=nil then goto Fend ;
DestIP := inet_addr(PChar(IPstr));
pMacAddr := @MacAddr[0];
AddrLen := SizeOf(MacAddr);
SendARP(DestIP, 0, pMacAddr, AddrLen);
p := PByte(pMacAddr);
if Assigned(p) and (AddrLen>0) then
for i := 0 to AddrLen-1 do
begin
s := s + IntToHex(p^,2);// + '-';
Inc(p);
end;
if trim(s)='' then
result:='-1'
else
Result:=pchar(s);
Fend:
FreeLibrary(hm);
end;exports
amchange, //function amchange(pas:pchar):pchar;stdcall;
bmchange, //function bmchange(pas:pchar;pasb:pchar):integer;stdcall;
imgr, //function imgr(server,database,user,password,path:pchar;number:integer):integer;stdcall;
imgw, //function imgw(server,database,user,password,path:pchar;number:integer):integer;stdcall;
getmac, //function getmac():pchar;
pron, //function pron(mac:pchar):integer;stdcall;
getip;
end.1.amchange(pas:pchar):pchar
功能:加密字符串。
参数:pas:需加密的字符串
返回:加密后的字符串(加长2-3个字符)2.bmchange(pas:pchar;pasb:pchar):integer
功能:判断两个加密字符串是否相等
参数:pas: 第一个加密字串
pasb:第二个加密字串
返回:0:两个字符串相等
-1:两个字符串不相等3.imgr(server,database,user,password,path:pchar;number:integer):integer
功能:读取'st'表'ft'(图像)字段
参数:server:数据服务器名称
database:数据库名称
user:登陆用户
password:登陆用户口令
path:图像的存盘路径(JPG文件格式)
number:字段'xh'( 序号)的值(指定要读取的图像)
返回:0:成功
-1:失败4.imgw(server,database,user,password,path:pchar;number:integer):integer
功能:更新'st'表'ft'(图像)字段
参数:server:数据服务器名称
database:数据库名称
user:登陆用户
password:登陆用户口令
path:读取图像的路径(bmp,jpg文件格式)
number:字段'xh'( 序号)的值(指定要更新的图像)
返回:0:成功
-1:失败5.GetMac():pchar
功能:返回本机网卡号
参数:无
返回:本机网卡号6.pron(mac:pchar):integer
功能:远程开机
参数:mac:网卡号(12位)
返回:0:成功
-1:失败
大部份都是我从CSDN抄来的...忘记都是谁的代码了,总之不是我写的.library NetTool;uses
SysUtils,
Windows,
Classes,
db,
graphics,
jpeg,
Winsock,
NMUDP,
dm in 'dm.pas' {DM1: TDataModule};type
IPAddr = Cardinal;
PSendARP=function (const DestIP, SrcIP: IPAddr;PMacAddr :PULong; var PhyAddrLen: ULong):dword;stdcall;
{$R *.res}function amchange(pas:pchar):pchar;stdcall; //加密
var
s1,s2:String;
i:Integer;
j,k:byte;
begin
s2:='';
s1:=pas;
repeat
Randomize;
j:=random(15);
until j>0;
For i:=1 to length(s1) Do
begin
k:=ord(s1[i]);
asm
mov dl,k
mov dh,j
xor dl,dh
mov k,dl
end;
s1[i]:=chr(k);
end;
s2:=s1+inttostr(j);
if j<=9 then s2:=s2+'1';
if j>9 then s2:=s2+'2';
amchange:=pchar(s2);
end;function bmchange(pas:pchar;pasb:pchar):integer;stdcall; //解密
var
s1,s2,s3:String;
i:Integer;
j,k:byte;
begin
try
s1:=pas;
if strtoint(s1[length(s1)])=1 then
begin
j:=strtoint(s1[length(s1)-1]);
delete(s1,length(s1)-1,2);
end
else begin
j:=strtoint(s1[length(s1)-2]+s1[length(s1)-1]);
delete(s1,length(s1)-2,3);
end;
For i:=1 to length(s1) Do
begin
k:=ord(s1[i]);
asm
mov dl,k
mov dh,j
xor dl,dh
mov k,dl
end;
s1[i]:=chr(k);
end;
s2:=s1;
//**********************************
s1:=pasb;
if strtoint(s1[length(s1)])=1 then
begin
j:=strtoint(s1[length(s1)-1]);
delete(s1,length(s1)-1,2);
end
else begin
j:=strtoint(s1[length(s1)-2]+s1[length(s1)-1]);
delete(s1,length(s1)-2,3);
end;
For i:=1 to length(s1) Do
begin
k:=ord(s1[i]);
asm
mov dl,k
mov dh,j
xor dl,dh
mov k,dl
end;
s1[i]:=chr(k);
end;
s3:=s1;
except
s2:='a';
s3:='b';
end;
//************************
if trim(s2)=trim(s3) then
bmchange:=0
else
bmchange:=-1;
end;function imgr(server,database,user,password,path:pchar;number:integer):integer;stdcall; //存取图像
var
dm1:TDM1;
begin
try
dm1:=TDM1.Create(nil);
dm1.ADOC1.ConnectionString:='Provider=SQLOLEDB.1;Password='+trim(password)+';Persist Security Info=True;User ID='+trim(user)+';Initial Catalog='+trim(database)+';Data Source='+trim(server)+';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;';
dm1.ADOC1.Connected:=true;
dm1.ADOQuery1.Close;
dm1.ADOQuery1.SQL.Clear;
dm1.ADOQuery1.SQL.Add('select ft from st where xh=:a');
dm1.ADOQuery1.Parameters.ParamValues['a']:=number;
dm1.ADOQuery1.Open;
dm1.ADOQuery1Ft.SaveToFile(trim(path));
imgr:=0;
except
imgr:=-1;
end;
dm1.ADOQuery1.Close;
dm1.ADOC1.Connected:=false;
end;function imgw(server,database,user,password,path:pchar;number:integer):integer;stdcall;
var
dm1:TDM1;
jp:TJPEGImage;
bm:Tbitmap;
Stream:TMemoryStream;
filee,filename:string;
begin
try
dm1:=TDM1.Create(nil);
bm:=Tbitmap.Create;
jp:=TJPEGImage.Create;
stream:=TMemoryStream.Create;
filename:=path;
filee:=copy(filename,length(filename)-2,3);
if filee='jpg' then
begin
jp.LoadFromFile(path);
end
else begin
bm.LoadFromFile(path);
jp.Assign(bm);
end;
jp.SaveToStream(stream);
dm1.ADOC1.ConnectionString:='Provider=SQLOLEDB.1;Password='+trim(password)+';Persist Security Info=True;User ID='+trim(user)+';Initial Catalog='+trim(database)+';Data Source='+trim(server)+';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;';
dm1.ADOC1.Connected:=true;
dm1.ADOQuery1.Close;
dm1.ADOQuery1.SQL.Clear;
dm1.ADOQuery1.SQL.Add('update st set ft=:b where xh=:a');
dm1.ADOQuery1.Parameters.ParamValues['a']:=number;
dm1.adoquery1.Parameters.ParamByName('b').LoadFromStream(stream,ftBlob);
dm1.ADOQuery1.ExecSQL;
stream.Free;
bm.Free;
jp.Free;
imgw:=0;
except
imgw:=-1;
end;
dm1.ADOQuery1.Close;
dm1.ADOC1.Connected:=false;
end;function pron(mac:pchar):integer;stdcall;
var
NMUDP1: TNMUDP;
s:string;
i:array[1..6] of byte;
cb:array[1..6] of char;
c:array[1..102] of char;
j,j1,ne:integer;
begin
NMUDP1:=TNMUDP.Create(nil);
s:=mac;
if length(s)<>12 then
begin
pron:=-1;
exit;
end;
i[1]:=strtoint('$'+copy(s,1,2));
i[2]:=strtoint('$'+copy(s,3,2));
i[3]:=strtoint('$'+copy(s,5,2));
i[4]:=strtoint('$'+copy(s,7,2));
i[5]:=strtoint('$'+copy(s,9,2));
i[6]:=strtoint('$'+copy(s,11,2));
for j:=1 to 6 do
begin
c[j]:=chr(255);
end;
for j:=1 to 6 do
begin
cb[j]:=chr(i[j]);
end;
ne:=0;
for j:=1 to 16 do
begin
ne:=ne+6;
for j1:=1 to 6 do
begin
c[j1+ne]:=cb[j1];
end;
end;
nmudp1.SendBuffer(c,102);
pron:=0;
end;function getip():pchar;stdcall;
var
ch:array[1..32] of Char;
i:Integer;
ip,ipstr:string;
WSData:TWSAData;
MyHost:PHostEnt;
begin
if WSAstartup(2,wsdata)<>0 then
begin
Result:='-1';
exit;
end;
if getHostName(@ch[1],32)<>0 then
begin
Result:='-1';
exit;
end;
MyHost:=GetHostByName(@ch[1]);
if MyHost=nil then
begin
Result:='-1';
exit;
end;
for i:=1 to 4 do
begin
ip:=inttostr(Ord(MyHost.h_addr^[i-1]));
ipstr:=ipstr+ip;
if i<4 then ipstr:=ipstr+'.';
end;
result:=pchar(ipstr);
end;function getmac():pchar;stdcall;
label Fend;
var
DestIP:IPAddr;
pMacAddr: PULong;
AddrLen: ULong;
MacAddr: array[0..5] of byte;
p: PByte;
s,ipstr: string;
i: integer;
SendARP:PSendARP;
HM:Thandle;
begin
ipstr:=getip();
if trim(ipstr)='' then
begin
Result:='-1';
exit;
end;
Result:='-1';
hm := loadlibrary('iphlpapi.dll');
if hm = 0 then goto Fend;
SendARP := getprocaddress(hm, 'SendARP');
if @SendARP=nil then goto Fend ;
DestIP := inet_addr(PChar(IPstr));
pMacAddr := @MacAddr[0];
AddrLen := SizeOf(MacAddr);
SendARP(DestIP, 0, pMacAddr, AddrLen);
p := PByte(pMacAddr);
if Assigned(p) and (AddrLen>0) then
for i := 0 to AddrLen-1 do
begin
s := s + IntToHex(p^,2);// + '-';
Inc(p);
end;
if trim(s)='' then
result:='-1'
else
Result:=pchar(s);
Fend:
FreeLibrary(hm);
end;exports
amchange, //function amchange(pas:pchar):pchar;stdcall;
bmchange, //function bmchange(pas:pchar;pasb:pchar):integer;stdcall;
imgr, //function imgr(server,database,user,password,path:pchar;number:integer):integer;stdcall;
imgw, //function imgw(server,database,user,password,path:pchar;number:integer):integer;stdcall;
getmac, //function getmac():pchar;
pron, //function pron(mac:pchar):integer;stdcall;
getip;
end.1.amchange(pas:pchar):pchar
功能:加密字符串。
参数:pas:需加密的字符串
返回:加密后的字符串(加长2-3个字符)2.bmchange(pas:pchar;pasb:pchar):integer
功能:判断两个加密字符串是否相等
参数:pas: 第一个加密字串
pasb:第二个加密字串
返回:0:两个字符串相等
-1:两个字符串不相等3.imgr(server,database,user,password,path:pchar;number:integer):integer
功能:读取'st'表'ft'(图像)字段
参数:server:数据服务器名称
database:数据库名称
user:登陆用户
password:登陆用户口令
path:图像的存盘路径(JPG文件格式)
number:字段'xh'( 序号)的值(指定要读取的图像)
返回:0:成功
-1:失败4.imgw(server,database,user,password,path:pchar;number:integer):integer
功能:更新'st'表'ft'(图像)字段
参数:server:数据服务器名称
database:数据库名称
user:登陆用户
password:登陆用户口令
path:读取图像的路径(bmp,jpg文件格式)
number:字段'xh'( 序号)的值(指定要更新的图像)
返回:0:成功
-1:失败5.GetMac():pchar
功能:返回本机网卡号
参数:无
返回:本机网卡号6.pron(mac:pchar):integer
功能:远程开机
参数:mac:网卡号(12位)
返回:0:成功
-1:失败
解决方案 »
- Delphi和VC Socket连接问题!各位老大帮帮忙!急!
- 为什么有“缺少更新或刷新的键列信息”错误?
- Delphi中一个窗体跟另一个窗体怎样的方式通信才最好呢?请大家谈谈!螃蟹敬上
- 连接InterBase数据库的简单问题。在线等
- 请高手指点,关于类作为参数
- ado or odbc or bde?
- 高性能web服务器大征集。Delphi.Socket高手QQ大征集。
- 不知为什么?
- 请问哪有combobox的增强控件,可以放置图片的,用于图片的选择的控件?
- 怎样在Delphi进行统计
- 请问用TAdotable的什么方法能直接执行SQL语句?
- 如何实现捕获外部程序的输出,如运行Apache时会在Dos窗口输出 ~~Runing...,我如何用程序捕获这些输出
//加入nb3.pas单元
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,nb30;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
Function NBGetAdapterAddress(a:integer):String;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.lines.add('您的第'+edit1.text+'个适配器的MAC地址为'+NBGetAdapterAddress(StrtoInt(Edit1.Text)));
end;
function TForm1.NBGetAdapterAddress(a: integer): String;
//a指定多个网卡适配器中的哪一个0,1,2...
Var
NCB:TNCB; // Netbios control block file://NetBios控制块
ADAPTER : TADAPTERSTATUS; // Netbios adapter status//取网卡状态
LANAENUM : TLANAENUM; // Netbios lana
intIdx : Integer; // Temporary work value//临时变量
cRC : Char; // Netbios return code//NetBios返回值
strTemp : String; // Temporary string//临时变量
Begin
// Initialize
Result := '';
Try
// Zero control blocl
ZeroMemory(@NCB, SizeOf(NCB));
// Issue enum command
NCB.ncb_command:=Chr(NCBENUM);
cRC := NetBios(@NCB);
// Reissue enum command
NCB.ncb_buffer := @LANAENUM;
NCB.ncb_length := SizeOf(LANAENUM);
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Reset adapter
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBRESET);
NCB.ncb_lana_num := LANAENUM.lana[a];
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Get adapter address
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBASTAT);
NCB.ncb_lana_num := LANAENUM.lana[a];
StrPCopy(NCB.ncb_callname, '*');
NCB.ncb_buffer := @ADAPTER;
NCB.ncb_length := SizeOf(ADAPTER);
cRC := NetBios(@NCB);
// Convert it to string
strTemp := '';
For intIdx := 0 To 5 Do
strTemp := strTemp + InttoHex(Integer(ADAPTER.adapter_address[intIdx]),2);
Result := strTemp;
Finally
End;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.lines.Clear;
end;