| View previous topic :: View next topic |
| Author |
Message |
Rubes_sw Valued Contributor


Joined: 11 Jun 2001 Posts: 625 Location: Northern Ireland
|
Posted: Thu Nov 13, 2003 9:31 am Post subject: DLL Creation |
|
|
I just wanted to post this here, because there is not much activity on the Developer forum:
Can anyone make a VDS DLL out of this deliphi code? (Its freeware, open source)
| Code: |
{
*** Get MAC Adress ***
*** by Filip Skalka, fip@post.cz ***
*** September 2002 ***
}
unit MACAdress;
interface
uses classes;
function GetMACAdresses(const Adresses:TStringList;const MachineName:string=''):integer;
function GetMACAdress(const MachineName:string=''):string;
implementation
uses NB30,sysutils;
type
ENetBIOSError=class(Exception);
function NetBiosCheck(const b:char):char;
begin
if b<>chr(NRC_GOODRET) then raise ENetBIOSError.create('NetBios error'#13#10'Error code '+inttostr(ord(b)));
result:=b;
end;
function AdapterToString(const Adapter:PAdapterStatus):string;
begin
with Adapter^ do Result :=Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',[Integer(adapter_address[0]),Integer(adapter_address[1]),Integer(adapter_address[2]), Integer(adapter_address[3]),Integer(adapter_address[4]), Integer(adapter_address[5])]);
end;
procedure MachineNameToAdapter(Name:string;var AdapterName:array of char);
begin
if Name='' then Name:='*' else Name:=ansiuppercase(Name);
Name:=Name+StringOfChar(' ',length(AdapterName)-Length(Name));
move(Name[1],AdapterName[0],length(AdapterName));
end;
function GetMACAdresses(const Adresses:TStringList;const MachineName:string=''):integer;
var i:integer;
NCB: PNCB;
Adapter:PAdapterStatus;
Lenum:PLanaEnum;
RetCode:char;
begin
Adresses.clear;
New(NCB);
New(Adapter);
New(Lenum);
try
Fillchar(NCB^,SizeOf(TNCB),0);
fillchar(Lenum^,SizeOf(TLanaEnum),0);
NCB.ncb_command:=chr(NCBENUM);
NCB.ncb_buffer:=Pointer(Lenum);
NCB.ncb_length:=SizeOf(Lenum);
NetBiosCheck(Netbios(NCB));
result:=ord(Lenum.Length);
for i:=0 to result-1 do
begin
Fillchar(NCB^,SizeOf(TNCB),0);
Ncb.ncb_command:=chr(NCBRESET);
Ncb.ncb_lana_num:=lenum.lana[i];
NetBiosCheck(Netbios(Ncb));
FillChar(NCB^,SizeOf(TNCB),0);
FillChar(Adapter^,SizeOf(TAdapterStatus),0);
Ncb.ncb_command:=chr(NCBASTAT);
Ncb.ncb_lana_num:=lenum.lana[i];
MachineNameToAdapter(MachineName,Ncb.ncb_callname);
Ncb.ncb_buffer:=Pointer(Adapter);
Ncb.ncb_length:=SizeOf(TAdapterStatus);
RetCode:=Netbios(NCB);
if RetCode in [chr(NRC_GOODRET),chr(NRC_INCOMP)] then Adresses.add(AdapterToString(Adapter));
end;
finally
Dispose(NCB);
Dispose(Adapter);
Dispose(Lenum);
end;
end;
function GetMACAdress(const MachineName:string=''):string;
var stringlist:tstringlist;
begin
stringlist:=tstringlist.create;
try
if GetMACAdresses(stringlist,MachineName)=0 then result:='' else result:=stringlist[0];
finally
stringlist.destroy;
end;
end;
end.
|
I don't know anyone about delphi, but this is supposed to retrieve the MAc ID of a device.
Also I do note know what language this is (Maybe VB), can retrieve bytes sent/receive and other info:
| Code: |
typedef struct _MIB_IFROW {
WCHAR wszName[MAX_INTERFACE_NAME_LEN];
DWORD dwIndex; // index of the interface
DWORD dwType; // type of interface
DWORD dwMtu; // max transmission unit
DWORD dwSpeed; // speed of the interface
DWORD dwPhysAddrLen; // length of physical address
BYTE bPhysAddr[MAXLEN_PHYSADDR]; // physical address of adapter
DWORD dwAdminStatus; // administrative status
DWORD dwOperStatus; // operational status
DWORD dwLastChange; // last time operational status changed
DWORD dwInOctets; // octets received
DWORD dwInUcastPkts; // unicast packets received
DWORD dwInNUcastPkts; // non-unicast packets received
DWORD dwInDiscards; // received packets discarded
DWORD dwInErrors; // erroneous packets received
DWORD dwInUnknownProtos; // unknown protocol packets received
DWORD dwOutOctets; // octets sent
DWORD dwOutUcastPkts; // unicast packets sent
DWORD dwOutNUcastPkts; // non-unicast packets sent
DWORD dwOutDiscards; // outgoing packets discarded
DWORD dwOutErrors; // erroneous packets sent
DWORD dwOutQLen; // output queue length
DWORD dwDescrLen; // length of bDescr member
BYTE bDescr[MAXLEN_IFDESCR]; // interface description
} MIB_IFROW,*PMIB_IFROW;
--------------------------------------------------------------------
typedef DWORD (_stdcall *TGetIfTable) (
MIB_IFTABLE *pIfTable, // buffer for interface table
ULONG *pdwSize, // size of buffer
BOOL bOrder // sort the table by index?
);
...
TGetIfTable pGetIfTable;
...
// not so safe here...
pGetIfTable=(TGetIfTable)GetProcAddress(LoadLibrary("Iphlpapi.dll"),"GetIfTable");
/* always remember to test the result of LoadLibrary
and GetProcAddress against null return values... */
-------------------------------------------------------------------------
...
m_pTable=NULL;
m_dwAdapters=0;
ULONG uRetCode=pGetIfTable(m_pTable,&m_dwAdapters,TRUE);
if (uRetCode == 122 /* The data area passed to a system call is too small.*/)
{
// now we know how much memory allocate
m_pTable=new MIB_IFTABLE[m_dwAdapters];
pGetIfTable(m_pTable,&m_dwAdapters,TRUE);
for (UINT i=0;i<m_pTable->dwNumEntries;i++)
{
MIB_IFROW Row=m_pTable->table[i];
char szDescr[MAXLEN_IFDESCR];
memcpy(szDescr,Row.bDescr,Row.dwDescrLen);
szDescr[Row.dwDescrLen]=0;
m_ctlCBAdapters.AddString(szDescr);
}
}
...
-----------------------------------------------------------------------------
void CP01Dlg::UpdateCounters()
{
int nIndex=m_ctlCBAdapters.GetCurSel();
if (nIndex!=CB_ERR)
{
pGetIfTable(m_pTable,&m_dwAdapters,TRUE);
MIB_IFROW Row=m_pTable->table[nIndex];
m_strInfo.Format("Received %d, Sent %d",Row.dwInOctets,Row.dwOutOctets);
UpdateData(FALSE);
}
}
|
Can anyone make any VDS DLLs out of this code ? PLEASE !!!
Nathan |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Nov 13, 2003 10:20 am Post subject: |
|
|
Threw together a really quick and dirty test DLL for MAC id part. Check your mail. No guarantees.
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Rubes_sw Valued Contributor


Joined: 11 Jun 2001 Posts: 625 Location: Northern Ireland
|
Posted: Thu Nov 13, 2003 11:34 am Post subject: |
|
|
Yep the Mac Address Test.dll works great, fast and reilable
Any chance of combining the bytes sent/recieved into the DLL or another DLL ?
I know i'm asking a lot, but you are doing a great job!
Nathan |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Nov 13, 2003 12:06 pm Post subject: |
|
|
Glad the MAC id thingie works
Haven't got time to check the other one out - I think it's gonna be pretty hairy, though
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Nov 27, 2003 2:08 am Post subject: |
|
|
Nathan!
I tidied up things a bit. Put in a bit of error checking etc. Made a version 1.1 which is available at the vdsworld homepage.
Please observe that the DLL calling syntax has changed a bit
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Nov 27, 2003 2:13 am Post subject: |
|
|
Nice job on this. I can certainly use this too.  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Thu Nov 27, 2003 2:19 am Post subject: |
|
|
Thanks.
It was just lying around here after I built it for Nathan so I thought that I might put it out..
Greetz
Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|