Author Topic: Input/Output Text QUESTION =(  (Read 589 times)

Offline triumphost1

  • Newbie
  • *
  • Posts: 19
  • Rep: 0
    • View Profile
Input/Output Text QUESTION =(
« on: October 07, 2009, 11:02:55 pm »
The following code below outputs the IPconfig/all command information to a text file... The problem Ive been having all day is that I dont know how to make it read certain parts of the text file and output that on screen or to another text file... For example: This is what my program prints to the file and I want it to read the PHYSICAL ADDRESS.... XX-AA-BB-CC-DD-YY  where the letters are just variables that can be any alpha-numerical values which is different for each computer. I just cant seem to get it to read the values of the physical address... Pls help I tried using getline command, fstream, etc it reads the whole file instead of just the values of the address

Code: [Select]

Windows IP Configuration



        Host Name . . . . . . . . . . . . : OWNER

        Primary Dns Suffix  . . . . . . . :

        Node Type . . . . . . . . . . . . : Broadcast

        IP Routing Enabled. . . . . . . . : No

        WINS Proxy Enabled. . . . . . . . : No

        DNS Suffix Search List. . . . . . : XXXXXXXXXXX



Ethernet adapter Local Area Connection:



        Connection-specific DNS Suffix  . : XXXXXXXXXX

        Description . . . . . . . . . . . : Integrated Controller

        Physical Address. . . . . . . . . : XX-AA-BB-CC-DD-YY

        Dhcp Enabled. . . . . . . . . . . : Yes

        Autoconfiguration Enabled . . . . : Yes

        IP Address. . . . . . . . . . . . : xx.xx.xx.xxx

        Subnet Mask . . . . . . . . . . . : 255.255.255.248

        Default Gateway . . . . . . . . . : xx.xx.xx.xx

        DHCP Server . . . . . . . . . . . : 192.xxx.x.x

        DNS Servers . . . . . . . . . . . : 192.xxx.x.x

        Lease Obtained. . . . . . . . . . : Thursday, October 08, 2009 1:15:25 AM

        Lease Expires . . . . . . . . . . : Thursday, October 08, 2009 1:25:25 AM




This is the start of my code because I erased the rest of it since it reads the information I dont want... I only want the physical address value =(

Code: [Select]
//Source Code

#include <windows.h>
#include <math.h>
#include <winuser.h>
#include <stdio.h>
#include <fstream>

using namespace std;

int main()
{
    cout<<"Welcome to Installation Helper\n";
    system("ipconfig/all >> C:\\ipInfo.txt");
    cout<<"\n";
    Sleep(1000);
}

Posted on: October 07, 2009, 10:34:40 PM
OK I Found this and I dont know how to print it to a text file:
Code: [Select]
#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>
#pragma comment(lib, "Netapi32.lib")

// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}

// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
unsigned char MACData[8]; // Allocate data structure for MAC (6 bytes needed)

WKSTA_TRANSPORT_INFO_0 *pwkti; // Allocate data structure for Netbios
DWORD dwEntriesRead;
DWORD dwTotalEntries;
BYTE *pbBuffer;
   
// Get MAC address via NetBios's enumerate function
NET_API_STATUS dwStatus = NetWkstaTransportEnum(
NULL, // [in]  server name
0, // [in]  data structure to return
&pbBuffer, // [out] pointer to buffer
MAX_PREFERRED_LENGTH, // [in]  maximum length
&dwEntriesRead, // [out] counter of elements actually enumerated
&dwTotalEntries, // [out] total number of elements that could be enumerated
NULL); // [in/out] resume handle
assert(dwStatus == NERR_Success);

pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer; // type cast the buffer

for(DWORD i=1; i< dwEntriesRead; i++) // first address is 00000000, skip it
{ // enumerate MACs and print
swscanf((wchar_t *)pwkti[i].wkti0_transport_address, L"%2hx%2hx%2hx%2hx%2hx%2hx",
&MACData[0], &MACData[1], &MACData[2], &MACData[3], &MACData[4], &MACData[5]);
PrintMACaddress(MACData);
}

// Release pbBuffer allocated by above function
dwStatus = NetApiBufferFree(pbBuffer);
assert(dwStatus == NERR_Success);
}

int _tmain(int argc, _TCHAR* argv[])
{
GetMACaddress(); // Obtain MAC address of adapters

return 0;
}


Freddy1990.com

Input/Output Text QUESTION =(
« on: October 07, 2009, 11:02:55 pm »

 

deductible-aliform