March 28, 2024, 05:30:16 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Calculating my mac address

Started by Andy, May 15, 2018, 01:17:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

I know my mac address is as follows:

00-11-6B-C1-43-4D

There are two entries stored in the registry for this address (a low part and a high part):

High value is  1c6f           (7279 decimal)
Low  valus is  65798619  (1702463001 decimal)

Does anyone know how you combine these two to arrive at 00-11-6B-C1-43-4D?

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

May 15, 2018, 03:40:45 AM #1 Last Edit: May 15, 2018, 03:43:59 AM by Egil
Andy,
The mac addresses are hard wired into the computer network interface cards at manufacture. Don't think it is possible to calculate them.
See also: https://whatismyipaddress.com/mac-address

Egil
Support Amateur Radio  -  Have a ham  for dinner!

Andy

Egil,

Interesting post, but there must be a way.

Okay, let's ask an alternative question,
how do I invoke CMD.exe and use the switch "ipconfig /all" and send the output using ">" to a text file.

The first way would be better, but if not, how about the cmd.exe with the switch method?

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Found how to do it to a text file:

openconsole
system "cmd.exe","/c ipconfig /all > c:\\1\\1.txt"
do:until inkey$ <> ""
closeconsole
end


Where c:\\1 is a folder called 1 on the C drive, and the text file is called 1.txt

But the registry way would be better.
Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

May 15, 2018, 11:27:44 AM #4 Last Edit: May 15, 2018, 11:29:42 AM by Brian Pugh
Andy,

There is a useful program called getmac. Go into cmd prompt, and type getmac /? to see the possible combinations

And there is also arp -a - this call lists the adapter MAC addresses as well as the internal Windows MAC addresses that are generated

Brian

Andy

Thanks Brian,

I will have a look at that tomorrow.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

Hi, guys. A computer can have any number of network adapters, so there's no requirement that there is just one MAC address. An alternative to CMD commands is GetAdaptersInfo


$INCLUDE "windowssdk.inc"
$INCLUDE "Iphlpapi.inc"

$USE "Iphlpapi.lib"

DECLARE CDECL EXTERN _sprintf(buf as STRING, format as STRING, ...),INT

OPENCONSOLE
PRINT
PrintAdapters()

PRINT
PRINT "Press any key to exit"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE

SUB PrintAdapters()
IP_ADAPTER_INFO AdapterInfo[20]
DWORD dwBufLen = LEN(AdapterInfo)
DWORD dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufLen) 

pointer p = &AdapterInfo + 0
SETTYPE p, IP_ADAPTER_INFO

WHILE p
PRINT *p.Description

string mac_addr
_sprintf(mac_addr, "%02X-%02X-%02X-%02X-%02X-%02X", *p.Address[0], *p.Address[1], *p.Address[2], *p.Address[3], *p.Address[4], *p.Address[5])
PRINT mac_addr
PRINT

p = *p._Next + 0
ENDWHILE
ENDSUB


Andy

Fasecero,

I did see something like this in c++ or c# I think it was, but there was just no way I could have translated it to IWB.

The code works perfectly on my PC, I do understand you can have multiple MACs on each machine, but this code does exactly what I was after.

Thanks,
Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Just one question:

In the structure of IP_ADAPTER_INFO,  we have a field called "Type".

I would love to get this data, but TYPE is a reserved word, so how can I include this:

      PRINT *p.Type - gives a syntax error!
      PRINT *p.Description - this is okay.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

try using pointer math -
*p.Type is an UINT and in the structure follows *p.INDEX  which is a DWORD
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

fasecero


Congrats Andy, you have found a secret Easter egg! :) Nah, what is really happening is that 'Type' is a reserved word and in these cases Sapero was forced to change the variable name usually by putting an underscore prefix. This will happen in any BASIC dialect because by definition BASIC isn't case sensitive, so 'Next', 'NEXT', 'next' they all are the same to the compiler. On the other hand, both C and C++ are case sensitive, so 'next' is a reserved word but 'Next' isn't, so they can use it. Search for (Sapero) IP_ADAPTER_INFO header declaration and you'll see that it appears like this

type IP_ADAPTER_INFO
pointer _Next ' Next on MSDN (another reserved word)
...
UINT _Type ' Type on MSDN
...
endtype


So *p._type should do the trick.

Quotetry using pointer math -
*p.Type is an UINT and in the structure follows *p.INDEX  which is a DWORD

It can also be done this way :)

Andy

Thanks guys,

That does give the type of the adaptor, it returns types 6 and 71, which is correct according to MSDN.  :)

Perhaps one final question on this:

I have 1 internal on board lan, and 1 USB WiFi adaptor.

The on board lan doesn't work (although it states in windows it's working correctly - and let's no go into why), so I use the USB WiFi adaptor for the Internet instead.

Now because I have a USB WiFi adaptor, the program also lists a "Microsoft Virtual WiFi Miniport adaptor" as well.

Now this Miniport adaptor is a "Virtual adaptor" - so the obvious question is this:

How can I tell if an adaptor is a physical one, or a virtual one?

Thanks for all your help,
Andy.






Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

May 23, 2018, 06:21:49 AM #12 Last Edit: May 23, 2018, 07:17:35 AM by Brian Pugh
Andy,

Have you seen this one? Don't understand it, but that's nothing new for me!

Brian

Andy

May 23, 2018, 06:27:59 AM #13 Last Edit: May 23, 2018, 06:39:23 AM by Andy
Brian,

That's something to think about, good find!

I had to alter the wbemdisp.inc file to this:

$ifndef __wbemdisp_inc__
$define __wbemdisp_inc__
$endif


There was a missing EndIf.

It does state the WiFi USB adaptor was the only one connected, but it does take a few seconds before it gives the results.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Funny. I wonder if your wbemdisp.inc include file is different to mine - I don't get any compile error

And it displays nearly instantly for me

Brian

Egil

May 23, 2018, 11:38:12 AM #15 Last Edit: May 23, 2018, 11:40:49 AM by Egil
Getting the same missing ENDIF error here, but after correcting the inc file, Brians code compiled ok.
I also checked the wbemdisp.inc in my EB distro, and found the same error there. So maybe that file should be corrected in the next updated distro?


Egil



PS
Almost forgot.... nice work Anndy!
Support Amateur Radio  -  Have a ham  for dinner!

Andy

May 27, 2018, 04:51:51 AM #16 Last Edit: May 27, 2018, 04:56:44 AM by Andy
Egil,

Thanks for the compliment, but the code was not done by me - but thanks anyway!

With the two bits of code together, we should be able to get the mac address of the actual active network adaptor.

The first code lists all network adaptors by name plus their mac address, the second lists all network adaptors by name and states which one is connected, so it's a simple task to put the two together.

Thanks every one!
Andy.
:) 
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.