BaH.MACAddress
BlitzMax Forums/Brucey's Modules/BaH.MACAddress
| ||
Because the world always has room for yet another cross-platform module.... BaH.MACAddress is a small utility module which uses a standard cross-platform API to retrieve the MAC address of your PC. It consists of two functions : Function GetMACAddress:Int[]() Function GetMACAddressString:String(uppercase:Int = True) GetMACAddress() returns an array of 6 ints. GetMACAddressString() returns a String of the form 00:00:00:00:00:00 Currently in SVN, but I'll do a release once I've given the Linux code a proper test. Notes : This retrieves only 1 MAC address. If you have 12 network cards installed, it will retrieve only 1 MAC address. |
| ||
Hooray! Thank you Brucey :-) |
| ||
No worries ;-) I only noticed your "request" for it this morning in the other thread... I thought it was better to be more generic than tied to wx. |
| ||
Hey, sort of related to this: Are you aware of any way to retrieve the netmask used by a network card? Blitz can natively find the IP addresses, but without knowing the netmask you can't determine the broadcast address for your network segment... |
| ||
Another little useful extension from you! *is envy of Brucey coding skills* Thanks. ;D |
| ||
This is a nice adition but what card gets chosen? If for example you have wireless network and a wired? |
| ||
These two related questions : Are you aware of any way to retrieve the netmask used by a network card? what card gets chosen? got me thinking. I'm now thinking that it may be more useful to be able to retrieve information on all the "network interfaces" installed on the local machine. This will include MAC addresses for each, and all the relevant other stuff, like netmask, broadcast, ip address, ipv6 address, etc. I'm looking into it. :-p |
| ||
Great! |
| ||
This is looking promising :Interface : en0 IP Address : 192.168.2.1 Netmask : 255.255.255.0 Broadcast : 192.168.2.255 MACAddress : xx:xx:xx:xx:xx:xx Stored in a type like this : Type TInet Field name:String Field address:Int Field MACAddress:Int[] Field MACAddressString:String Field netmask:Int Field broadcast:Int End Type A function, GetInetInterfaces() retrieves the list of interfaces. Comparing the output to ifconfig, it produces the same list. Working so far on Mac. Linux should be easier to implement. Windows... well, we'll see. Should it also retrieve "flags" (eg. UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST) etc? |
| ||
Oh my. Is there anything you can't do?! :P |
| ||
Great. Now its alot more usefull :) I do this with a vbs script for the moment so this is a good development |
| ||
I have this on Win32 now :Interface : {XXXXXXXX-4D1E-4018-84CF-FEE91BXXXXXX} IP Address : 10.211.55.3 Netmask : 255.255.255.0 Broadcast : 10.211.55.255 MACAddress : xx:xx:xx:xx:xx:xx Windows doesn't seem to have a simple interface name... but I don't suppose it matters really? It's producing the same output as ipconfig. I should probably change the name of the module to BaH.inet or something now... |
| ||
Right, I've changed the name to BaH.Inet.... and committed the work so far. It appears to be working on Mac and Win32. I'm about to investigate Linux now. |
| ||
Also working now for Linux. Possible enhancements : * Maybe removing the loopback interface from the list, since it seems a bit redundant. * Adding "flags". |
| ||
Works like a charm under Win32 -- and unlike the built-in Blitz command to get the IP address, this is instant (the built-in command takes like 5-10 seconds to return my IP address last time I tried it) There should be *some* way to get the proper interface names, though - ipconfig labels them "local area network", "VMware Network Adapter VMnet1", etc. |
| ||
There should be *some* way to get the proper interface names, though I imagine there is. I could get the description field, but when I tried that, it came back with the name of the actual hardware. I'll do some more research :-p |
| ||
Brucey, this is exactly what i was looking for. Bmax wouldn't be the same thing without you, (and neither my project he he..) Thank you very much!! :) |
| ||
Brucey, i when i try to run your example_01.bmx, i get this error: "../BlitzMax/bin/ld.exe: cannot find -lrpcrt4" it's a dll i need to have in my directory or something? Thanks! |
| ||
i get this error... okay, I've removed that requirement now. It was original required in an early build of the module. It seems that the move to a different API means that is no longer required. Hope that works for you now. |
| ||
Whoa! ultra fast reply he he.. Tried again with your recent fix, but this time i get this error: BlitzMax/bin/ld.exe: cannot find -liphlpapi Checked your source, and there are 2 imports: Import "-lws2_32" Import "-liphlpapi" Removed the import line but it seems the module needs that line to work |
| ||
I'm afraid libiphlpapi.a is required for this to work. It is in your MinGW distribution. Unfortunately, BlitzMax/lib does not include all of the .a files that you might need... only a subset. If you browse to your MinGW/lib folder in explorer, you should see libiphlpapi.a there. You can copy that to your BlitzMax/lib folder. Maybe I should ask Mark nicely if he wouldn't mind providing the full set of library files... then it would save you the trouble of copying them yourself. |
| ||
Hey, thanks for your quick reply :) It's ok, you do more than enough by making this modules for the community so, moving files from one place to another is nothing. Thanks for your help and your great modules. |
| ||
After a lot of searching, and searching, and trial and error, I've finally got Win32 to display the correct "ethernet adapter" as the name field. Eg :Interface : Local Area Connection 2 IP Address : 10.225.122.150 Netmask : 255.255.255.0 Broadcast : 10.225.122.255 MAC Address : xx:xx:xx:xx:xx:xx Can some of you check that it is returning the correct information for you please? It should match up to what ipconfig says... Thanks. |
| ||
Added support for "flags" on Mac and Win32. Linux to follow :Interface : Local Area Connection 3 : UP, BROADCAST, MULTICAST IP Address : 10.211.55.3 Netmask : 255.255.255.0 Broadcast : 10.211.55.255 MAC Address : xx:xx:xx:xx:xx:xx |
| ||
is there a way of checking if ports are open? |
| ||
Looks like the updated version works:Interface : Local Area Connection : UP, BROADCAST, MULTICAST IP Address : 192.168.1.2 Netmask : 255.255.255.0 Broadcast : 192.168.1.255 MAC Address : xx:xx:xx:xx:xx:xx Interface : VMware Network Adapter VMnet1 : UP, BROADCAST, MULTICAST IP Address : 192.168.0.1 Netmask : 255.255.255.0 Broadcast : 192.168.0.255 MAC Address : xx:xx:xx:xx:xx:xx Interface : VMware Network Adapter VMnet8 : UP, BROADCAST, MULTICAST IP Address : 192.168.249.1 Netmask : 255.255.255.0 Broadcast : 192.168.249.255 MAC Address : xx:xx:xx:xx:xx:xx (disabling my local area network adapter dropped it from the list of returned information as well.) |
| ||
is there a way of checking if ports are open? Like with the command-line tool netstat ? I imagine so. |
| ||
Here's some PureBasic code (sorry) I wrote not so long ago -- this shows the method for retrieving a netstat-like list of open ports: |
| ||
Here's some PureBasic code Yuck... :-p But thanks :-) That PHP(sic) dll is coming in quite handy. On Linux, everything apparently lives in /proc/net/tcp I'm still rummaging around for the Mac stuff. |
| ||
This is pretty nice, missed this thread origianlly, thanks Brucey for the work on this. Could come in very handy. |
| ||
Now that I'm actually using this I wanted to add: what a wonderful, easy to use interface you've given us Brucey. Thank you! |