Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MainForm.cpp
- #include "MainForm.h"
- using namespace System;
- using namespace System::Windows::Forms;
- [STAThreadAttribute]
- void Main(array<String^>^ args) {
- Application::EnableVisualStyles();
- Application::SetCompatibleTextRenderingDefault(false);
- WinForms_CN::MainForm form;
- Application::Run(%form);
- }
- //MainForm.h
- #pragma once
- #include <windows.h>
- #include <iphlpapi.h>
- #include <iostream>
- #pragma comment (lib, "IPHlpApi.Lib")
- #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
- namespace WinForms_CN {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- public ref class MainForm : public System::Windows::Forms::Form
- {
- public:
- MainForm(void)
- {
- InitializeComponent();
- }
- protected:
- ~MainForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::Button^ button1;
- private: System::Windows::Forms::TextBox^ textBox1;
- protected:
- private:
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- void InitializeComponent(void)
- {
- this->button1 = (gcnew System::Windows::Forms::Button());
- this->textBox1 = (gcnew System::Windows::Forms::TextBox());
- this->SuspendLayout();
- //
- // button1
- //
- this->button1->Location = System::Drawing::Point(12, 12);
- this->button1->Name = L"button1";
- this->button1->Size = System::Drawing::Size(130, 23);
- this->button1->TabIndex = 0;
- this->button1->Text = L"Get Information";
- this->button1->UseVisualStyleBackColor = true;
- this->button1->Click += gcnew System::EventHandler(this, &MainForm::button1_Click);
- //
- // textBox1
- //
- this->textBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
- | System::Windows::Forms::AnchorStyles::Left)
- | System::Windows::Forms::AnchorStyles::Right));
- this->textBox1->Font = (gcnew System::Drawing::Font(L"Courier New", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->textBox1->Location = System::Drawing::Point(12, 41);
- this->textBox1->Multiline = true;
- this->textBox1->Name = L"textBox1";
- this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
- this->textBox1->Size = System::Drawing::Size(400, 405);
- this->textBox1->TabIndex = 1;
- //
- // MainForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(424, 461);
- this->Controls->Add(this->textBox1);
- this->Controls->Add(this->button1);
- this->Name = L"MainForm";
- this->Text = L"Lab_5 CN";
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: String^ addressToStr(BYTE* address) {
- String ^st;
- int max = sizeof(address) / sizeof(address[0])+2;
- for (int i = 0; i < max; i++)
- {
- char buff[4];
- if (i<max - 1)
- sprintf(buff, "%02x-", (unsigned char)address[i]);
- else
- sprintf(buff, "%02x", (unsigned char)address[i]);
- st = st + gcnew String(buff);
- }
- return st;
- }
- private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
- textBox1->Text += "*** Basic Network Settings ***\r\n";
- FIXED_INFO *pFixedInfo;
- ULONG ulOutBufLen;
- DWORD dwRetVal;
- IP_ADDR_STRING *pIPAddr;
- pFixedInfo = (FIXED_INFO *)MALLOC(sizeof(FIXED_INFO));
- ulOutBufLen = sizeof(FIXED_INFO);
- GetNetworkParams(pFixedInfo, &ulOutBufLen);
- textBox1->Text += "1.Host Name.............." + gcnew String(pFixedInfo->HostName) + "\r\n";
- textBox1->Text += "2.Domain Name............" + gcnew String(pFixedInfo->DomainName) + "\r\n";
- switch (pFixedInfo->NodeType) {
- case BROADCAST_NODETYPE:
- textBox1->Text += "3.Net BIOS..............." + gcnew String("Broadcast") + "\r\n";
- break;
- case PEER_TO_PEER_NODETYPE:
- textBox1->Text += "3.Net BIOS..............." + gcnew String("Peer to Peer") + "\r\n";
- break;
- case MIXED_NODETYPE:
- textBox1->Text += "3.Net BIOS..............." + gcnew String("Mixed") + "\r\n";
- break;
- case HYBRID_NODETYPE:
- textBox1->Text += "3.Net BIOS..............." + gcnew String("Hybrid") + "\r\n";
- break;
- }
- if (pFixedInfo->EnableRouting)
- textBox1->Text += "4.Routing................Enabled\r\n";
- else
- textBox1->Text += "4.Routing................Disabled\r\n";
- if (pFixedInfo->EnableProxy)
- textBox1->Text += "5.Proxy..................Enabled\r\n";
- else
- textBox1->Text += "5.Proxy..................Disabled\r\n";
- textBox1->Text += "6.DNS Servers............" + gcnew String(pFixedInfo->DnsServerList.IpAddress.String) + "\r\n";
- textBox1->Text += "*** Installed network adapters ***\r\n";
- PIP_ADAPTER_INFO pAdapterInfo;
- pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
- unsigned long buflen = sizeof(IP_ADAPTER_INFO);
- if (GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW) {
- free(pAdapterInfo);
- pAdapterInfo = (IP_ADAPTER_INFO *)malloc(buflen);
- }
- if (GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) {
- PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
- while (pAdapter) {
- textBox1->Text += "\r\n";
- textBox1->Text += gcnew String(pAdapter->AdapterName) + "\r\n";
- textBox1->Text += "1.Adapter Name..........." + gcnew String(pAdapter->AdapterName) + "\r\n";
- textBox1->Text += "2.Adapter Description...." + gcnew String(pAdapter->Description) + "\r\n";
- textBox1->Text += "3.Index.................." + pAdapter->Index.ToString() + "\r\n";
- textBox1->Text += "4.MAC Address............" + addressToStr(pAdapter->Address) + "\r\n";
- textBox1->Text += "5.Local IP Address......." + gcnew String(pAdapter->IpAddressList.IpAddress.String) + "\r\n";
- textBox1->Text += "6.IP Mask................" + gcnew String(pAdapter->IpAddressList.IpMask.String) + "\r\n";
- textBox1->Text += "7.Gateway................" + gcnew String(pAdapter->GatewayList.IpAddress.String) + "\r\n";
- if (pAdapter->DhcpEnabled) {
- textBox1->Text += "DHCP....................." + "Enabled\r\n";
- if ((gcnew String(pAdapter->DhcpServer.IpAddress.String))->Length != 0) {
- textBox1->Text += "DHCP Server.............." + gcnew String(pAdapter->DhcpServer.IpAddress.String) + "\r\n";
- struct tm newtime;
- char buffer[32];
- _localtime32_s(&newtime, (__time32_t*)&pAdapter->LeaseObtained);
- asctime_s(buffer, 32, &newtime);
- textBox1->Text += "Lease Obtained..........." + gcnew String(buffer) + "\r\n";
- _localtime32_s(&newtime, (__time32_t*)&pAdapter->LeaseExpires);
- asctime_s(buffer, 32, &newtime);
- textBox1->Text += "Lease Expires............" + gcnew String(buffer) + "\r\n";
- }
- }
- else {
- textBox1->Text += "DHCP....................."+ "Disabled\r\n";
- }
- pAdapter = pAdapter->Next;
- }
- }
- else {
- textBox1->Text += "Call to GetAdaptersInfo failed.\r\n";
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment