Mac Adresini Nasıl alabiliriz?

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
stnonstop
Üye
Mesajlar: 149
Kayıt: 22 Haz 2005 04:34

Mac Adresini Nasıl alabiliriz?

Mesaj gönderen stnonstop »

Acaba bilgisayarlarda olan ethernet kartlarının mac adreslerini alıp programımız içinde kullanabileceğimiz bir program yada compenent var mı ???
cemarik
Üye
Mesajlar: 45
Kayıt: 30 Ağu 2003 11:05
Konum: İzmir

Mesaj gönderen cemarik »

TurboPower ın Onguard Component Bileşenlerinde vardı yanılmıyorsam
stnonstop
Üye
Mesajlar: 149
Kayıt: 22 Haz 2005 04:34

Mesaj gönderen stnonstop »

malesef onguard compenentinde bununla ilgili bir şey bulamadım.
St. NonStop
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi
Kullanıcı avatarı
coskundeniz
Üye
Mesajlar: 22
Kayıt: 20 Ara 2003 11:36

Mesaj gönderen coskundeniz »

Aşağıda kod işini görecektir

Kod: Tümünü seç

function GetPrimaryNicMacAddress : string;
type
  TGUID = record
    A, B: word;
    D, M, S: word;
    MAC: array[1..6] of byte;
  end;
var
  UuidCreateFunc: function(var guid: TGUID): HResult; stdcall;
  handle: THandle;
  g: TGUID;
  WinVer: _OSVersionInfoA;
  i: integer;
begin
  WinVer.dwOSVersionInfoSize := sizeof(WinVer);
  getversionex(WinVer);

  handle := LoadLibrary('RPCRT4.DLL');
  if WinVer.dwMajorVersion >= 5 then {Windows 2000 }
    @UuidCreateFunc := GetProcAddress(Handle, 'UuidCreateSequential')
  else
    @UuidCreateFunc := GetProcAddress(Handle, 'UuidCreate');


  if UuidCreateFunc(g) = 0 then
  begin
    Result := '';
    for i := 1 to 6 do
    begin
      if Result <> '' then Result := Result + '-';
      result := result + IntToHex(g.MAC[i], 2);
    end;
  end else result := '00-00-00-00-00-00';
end;
stnonstop
Üye
Mesajlar: 149
Kayıt: 22 Haz 2005 04:34

Mesaj gönderen stnonstop »

Birde arkadaşlar ipconifg /all komutunu tavsiye etmişlerdi bir yerde fakat bunu nasıl alacağız sonuçlarını filan örnek kod ??? anlatan bir yer link veya anlata bilecek birisi var mı ???
St. NonStop
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi
fduman
Moderator
Mesajlar: 2749
Kayıt: 17 Ara 2004 12:02
Konum: Ankara

Mesaj gönderen fduman »

Biraz arama ile hatta Aramada MAC yazınca..

viewtopic.php?t=7297&highlight=mac
stnonstop
Üye
Mesajlar: 149
Kayıt: 22 Haz 2005 04:34

Mesaj gönderen stnonstop »

Coderlord sizin gönderdiğiniz artikellı zaten biliyorum okudum. Saolsun coskundenizin verdiği kodtaki GUID yöntemini de konumuştum. Arama yapmamış değilim. merakım şudur. ipconfig /all komutunun nasıl gönderirim sonuçlarını nasıl alırım programıma onu merak ediyorum....
St. NonStop
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi
fduman
Moderator
Mesajlar: 2749
Kayıt: 17 Ara 2004 12:02
Konum: Ankara

Mesaj gönderen fduman »

Program çalıştırma ile ilgili kodu sitede bulabilirsin, onu vermiyorum.

1. yöntem: çalıştırırken "ipconfig /all > c:\ipconfig.txt" yapar ve ipconfig.txt içini okuyarak parse edersin. Bu komut ile ipconfig / all'un çıktısı c:\ipconfig.txt ye yazılacaktır.

2. yöntem:
http://delphi.about.com/cs/adptips2001/ ... 0201_2.htm
From Zarko Gajic,
Your Guide to Delphi Programming.
FREE Newsletter. Sign Up Now!
The example runs 'chkdsk.exe c:\' and displays the output to Memo1.
Put a TMemo (Memo1) and a TButton (Button1) on your form. Put this code in the OnCLick event procedure for Button1:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button1Click(Sender: TObject) ;

procedure RunDosInMemo(DosApp:String;AMemo:TMemo) ;
const
ReadBuffer = 2400;
var
Security : TSecurityAttributes;
ReadPipe,WritePipe : THandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
BytesRead : DWord;
Apprunning : DWord;
begin
With Security do begin
nlength := SizeOf(TSecurityAttributes) ;
binherithandle := true;
lpsecuritydescriptor := nil;
end;
if Createpipe (ReadPipe, WritePipe,
@Security, 0) then begin
Buffer := AllocMem(ReadBuffer + 1) ;
FillChar(Start,Sizeof(Start),#0) ;
start.cb := SizeOf(start) ;
start.hStdOutput := WritePipe;
start.hStdInput := ReadPipe;
start.dwFlags := STARTF_USESTDHANDLES +
STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;

if CreateProcess(nil,
PChar(DosApp),
@Security,
@Security,
true,
NORMAL_PRIORITY_CLASS,
nil,
nil,
start,
ProcessInfo)
then
begin
repeat
Apprunning := WaitForSingleObject
(ProcessInfo.hProcess,100) ;
Application.ProcessMessages;
until (Apprunning <> WAIT_TIMEOUT) ;
Repeat
BytesRead := 0;
ReadFile(ReadPipe,Buffer[0],
ReadBuffer,BytesRead,nil) ;
Buffer[BytesRead]:= #0;
OemToAnsi(Buffer,Buffer) ;
AMemo.Text := AMemo.text + String(Buffer) ;
until (BytesRead < ReadBuffer) ;
end;
FreeMem(Buffer) ;
CloseHandle(ProcessInfo.hProcess) ;
CloseHandle(ProcessInfo.hThread) ;
CloseHandle(ReadPipe) ;
CloseHandle(WritePipe) ;
end;
end;

begin {button 1 code}
RunDosInMemo('chkdsk.exe c:\',Memo1) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~
Bu da doğrudan bir TMemo içine çıktıyı gönderiyor.
stnonstop
Üye
Mesajlar: 149
Kayıt: 22 Haz 2005 04:34

Mesaj gönderen stnonstop »

Teşekkürler Faat bunu ben C ye çeviremedim bir türlü DLL olarak yayınlaya bilecek bir arkadaş var mı :(
St. NonStop
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi
Kullanıcı avatarı
bluekid
Kıdemli Üye
Mesajlar: 541
Kayıt: 11 Haz 2004 10:45
İletişim:

Mesaj gönderen bluekid »

Kod: Tümünü seç

Memo1->Clear();
 //create pipe for the console stdout
  SECURITY_ATTRIBUTES sa;
  ZeroMemory(&sa,sizeof(SECURITY_ATTRIBUTES));
  sa.nLength=sizeof(SECURITY_ATTRIBUTES);
  sa.bInheritHandle=true;
  sa.lpSecurityDescriptor=NULL;
  HANDLE ReadPipeHandle;
  HANDLE WritePipeHandle;       // not used here
  if(!CreatePipe(&ReadPipeHandle,&WritePipeHandle,&sa,0))
        RaiseLastWin32Error();

  //Create a Console
  STARTUPINFO si;

  ZeroMemory(&si,sizeof(STARTUPINFO));
  si.cb=sizeof(STARTUPINFO);
  si.dwFlags=STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
  si.wShowWindow=SW_HIDE;
  si.hStdOutput=WritePipeHandle;
  si.hStdError=WritePipeHandle;

  PROCESS_INFORMATION pi;
  ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
  if(!CreateProcess(CBox1->Text.c_str(),CBox2->Text.c_str(),NULL,NULL,true,0,NULL,NULL,&si,&pi))
      RaiseLastWin32Error();

  //Read from pipe
  char Data[1024];
  for (;;)
  {
    DWORD BytesRead;
    DWORD TotalBytes;
    DWORD BytesLeft;

    //Check for the presence of data in the pipe
    if(!PeekNamedPipe(ReadPipeHandle,Data,sizeof(Data),&BytesRead,
        &TotalBytes,&BytesLeft))RaiseLastWin32Error();
    //If there is bytes, read them
    if(BytesRead)
    {
      if(!ReadFile(ReadPipeHandle,Data,sizeof(Data)-1,&BytesRead,NULL))
          RaiseLastWin32Error();
      Data[BytesRead]='\0';
      Memo1->Lines->Add(AnsiString(Data));

    }
    else
    {
      //Is the console app terminated?
      if(WaitForSingleObject(pi.hProcess,0)==WAIT_OBJECT_0)break;

    }
  }
  CloseHandle(pi.hThread);
  CloseHandle(pi.hProcess);
  CloseHandle(ReadPipeHandle);
  CloseHandle(WritePipeHandle);
stnonstop
Üye
Mesajlar: 149
Kayıt: 22 Haz 2005 04:34

Mesaj gönderen stnonstop »

Çok teşekkürler. Tüm kodların bir zayıf noktası var galiba. Gönderdiğiniz kod mükemmel çalışıyor.
St. NonStop
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi
stnonstop
Üye
Mesajlar: 149
Kayıt: 22 Haz 2005 04:34

Mesaj gönderen stnonstop »

Kodu biraz geliştirdim. windows98 xp ve 2000 lerde çalışabilecek şekle getirmeye çalıştım.

Kod: Tümünü seç

AnsiString Path;
  int OSVersion;
  Memo1->Clear();
  TRegistry *Reg = new TRegistry;
  try
  {
    Reg->RootKey = HKEY_LOCAL_MACHINE;

    if (Reg->OpenKey("\\Software\\Microsoft\\Windows NT\\CurrentVersion", false))
    {
      if (Reg->ValueExists("SystemRoot"))
      {
        Path = Reg->ReadString("SystemRoot");
        OSVersion = 1;
      }
      else
      {
        Reg->CloseKey();
        if (Reg->OpenKey("\\Software\\Microsoft\\Windows\\CurrentVersion", false))
        {
          if (Reg->ValueExists("SystemRoot"))
          {
            Path = Reg->ReadString("SystemRoot");
            OSVersion = 0;
          }
        }
      }
      Reg->CloseKey();
    }
    //create pipe for the console stdout
    SECURITY_ATTRIBUTES sa;
    ZeroMemory(&sa,sizeof(SECURITY_ATTRIBUTES));
    sa.nLength=sizeof(SECURITY_ATTRIBUTES);
    sa.bInheritHandle=true;
    sa.lpSecurityDescriptor=NULL;
    HANDLE ReadPipeHandle;
    HANDLE WritePipeHandle;       // not used here
    if(!CreatePipe(&ReadPipeHandle,&WritePipeHandle,&sa,0))
          RaiseLastWin32Error();

    //Create a Console
    STARTUPINFO si;

    ZeroMemory(&si,sizeof(STARTUPINFO));
    si.cb=sizeof(STARTUPINFO);
    si.dwFlags=STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
    si.wShowWindow=SW_HIDE;
    si.hStdOutput=WritePipeHandle;
    si.hStdError=WritePipeHandle;

    PROCESS_INFORMATION pi;
    ZeroMemory(&pi,sizeof(PROCESS_INFORMATION));
    if (OSVersion == 1)
    {
      Path = Path+"\\system32\\ipconfig.exe";
      if(!CreateProcess(Path.c_str(), "ipconfig /all",NULL,NULL,true,0,NULL,NULL,&si,&pi))
          RaiseLastWin32Error();
    }
    else if (OSVersion == 0)
    {
       Path = Path+"\\ipconfig.exe";
       if(!CreateProcess(Path.c_str(), "ipconfig /all",NULL,NULL,true,0,NULL,NULL,&si,&pi))
           RaiseLastWin32Error();
    }

    //Read from pipe
    char Data[1024];
    for (;;)
    {
      DWORD BytesRead;
      DWORD TotalBytes;
      DWORD BytesLeft;

      //Check for the presence of data in the pipe
      if(!PeekNamedPipe(ReadPipeHandle,Data,sizeof(Data),&BytesRead,
          &TotalBytes,&BytesLeft))RaiseLastWin32Error();
      //If there is bytes, read them
      if(BytesRead)
      {
        if(!ReadFile(ReadPipeHandle,Data,sizeof(Data)-1,&BytesRead,NULL))
            RaiseLastWin32Error();
        Data[BytesRead]='\0';
        Memo1->Lines->Add(AnsiString(Data));
      }
      else
      {
        //Is the console app terminated?
        if(WaitForSingleObject(pi.hProcess,0)==WAIT_OBJECT_0)break;
      }
    }
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    CloseHandle(ReadPipeHandle);
    CloseHandle(WritePipeHandle);
  }
  __finally
  {
    delete Reg;
  }
St. NonStop
Aziz DURMAZ
Elektronik ve Haberleşme Mühendisi
Cevapla