11. november 2001 - 21:57
Der er
2 kommentarer og 1 løsning
Netværks informationer
Er der nogen der kender koden til at få default gateway og dns ip\'en, desuden ønsker jeg at få NIC mac-adressen, er der nogen der kan hjælpe ??
Annonceindlæg fra Cognizant
12. november 2001 - 22:40
#1
Et lille programm jeg lavede i Borland CppB, måske kan dette hjælpe lidt #include <vcl.h> #include <windows.h> #include <wincon.h> #include <nb30.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #include <winsock2.h> #pragma hdrstop #include \"Unit1.h\" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource \"*.dfm\" typedef struct _ASTAT_ { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff[30]; } ASTAT, * PASTAT; ASTAT Adapter; TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { NCB Ncb; UCHAR uRetCode; char NetName[50]; LANA_ENUM lenum; int ii; char str[255]; hostent *P; in_addr in; char *P2; WORD wVersionRequested; WSADATA WSAData; wVersionRequested = MAKEWORD(1,1); WSAStartup(wVersionRequested,&WSAData); memset (&Ncb, 0, sizeof(Ncb)); Ncb.ncb_command = NCBENUM; Ncb.ncb_buffer = (UCHAR*)&lenum; Ncb.ncb_length = sizeof (lenum); uRetCode = Netbios (&Ncb); sprintf (str, \"Number of Adapters: %d\", lenum.length); Memo1->Lines->Add(str); for (ii=0; ii < lenum.length ;ii++) { memset (&Ncb, 0, sizeof(Ncb)); Ncb.ncb_command = NCBRESET; Ncb.ncb_lana_num = lenum.lana[ii]; uRetCode = Netbios (&Ncb); memset (&Ncb, 0, sizeof (Ncb)); Ncb.ncb_command = NCBASTAT; Ncb.ncb_lana_num = lenum.lana[ii]; strcpy (Ncb.ncb_callname, \"* \"); Ncb.ncb_buffer = (char*) &Adapter; Ncb.ncb_length = sizeof (Adapter); uRetCode = Netbios (&Ncb); if (uRetCode == 0) { sprintf(str, \"MAC on Adapter %d is: %02x-%02x-%02x-%02x-%02x-%02x\", lenum.lana[ii], Adapter.adapt.adapter_address[0], Adapter.adapt.adapter_address[1], Adapter.adapt.adapter_address[2], Adapter.adapt.adapter_address[3], Adapter.adapt.adapter_address[4], Adapter.adapt.adapter_address[5] ); Memo1->Lines->Add (str); } } gethostname(str, 128); P = gethostbyname(str); sprintf (str, \"Hostname: %s\",P->h_name); Memo1->Lines->Add(str); in.S_un.S_un_b.s_b1 = P->h_addr_list[0][0]; in.S_un.S_un_b.s_b2 = P->h_addr_list[0][1]; in.S_un.S_un_b.s_b3 = P->h_addr_list[0][2]; in.S_un.S_un_b.s_b4 = P->h_addr_list[0][3]; P2 = inet_ntoa(in); sprintf (str, \"IP Address : %s\", P2); Memo1->Lines->Add(str); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { WSACleanup(); } //---------------------------------------------------------------------------
12. november 2001 - 23:08
#2
Hej futter2 Det jeg hovedsagelig leder efter er hvordan man får at vide hvad Default Gateway og DNS er på den lokale maskine, men det med MAC adresse kan jeg sagtens bruge, er der mulighed for at du kan lave et eksempel for mig ?