The Daily Click ::. Forums ::. Klik Coding Help ::. Obtaining a MAC address.
 

Post Reply  Post Oekaki 
 

Posted By Message

The_Antisony

At least I'm not Circy

Registered
  01/07/2002
Points
  1341

VIP MemberStarSnow
27th July, 2012 at 27/07/2012 20:39:57 -

I'm a computer technician, and I thought it might be nice to create an app that I can run on a client's machine that logs all the processes I run while I repair their computer. That's not the issue, though. I already have the app logging processes with dates and timestamps, but now I need to create some sort of non-cryptic system identifier. I know MAC addresses can be changed, but for all intensive purposes it's highly doubtful any of my clients would know how so I think it's a pretty safe machine identifier to use. I want to stick with the MAC address specifically because I need to be able to look up the system identifier easily outside of my app.

I don't think there's any extension that'll just produce a MAC address, so I did some research. Apparently the Console and Pipe objects might work, but there's not a single help file or example on the internet, and every time somebody seems to mention them, all they say is that "it's easy". Bull crap. If it were easy, both objects would be intuitive and I likely would have figured out how to use one or the other in the 2 hours I spent experimenting with them.

Back to the drawing board. I had to try this the hard way with a batch file. Since I'm attempting to keep this application portable so I can run it from a flash drive, I had to make the app create the batch file since otherwise I'd have to use static drive letters and app paths. So, I created an Edit Object and at the beginning of the frame, I set the text to "ipconfig /all > " + apppath$ +"ip.txt" and save the bat to apppath$ +"ip.bat" and execute the batch file which should dump the results from ipconfig /all into a text file in the application directory called ip.txt.

It works! Kinda. It works until the pathname supplied contains a space. Right now, my app resides in D:\Current Projects\process. The batch file ran, but exited without creating ip.txt, so I went back in and manually edited the batch file, changing "D:\Current Projects\process" to "D:\Curren~1\process" and the batch file worked and created ip.txt. Does that mean I have to convert to 8.3 path conventions, or is there some easier character substitute I could use to make the batch file work correctly?

If the console or pipe object would be any easier to use, I kinda need some explanation on how to use them or an example I could follow.

 
ChrisD> Employer: Say, wanna see a magic trick?
ChrisD> Employee: Uhh… sure, boss.
ChrisD> Employer: Your job! It just disappeared! Pack your things and leave! Pretty good trick, huh?

The_Antisony

At least I'm not Circy

Registered
  01/07/2002
Points
  1341

VIP MemberStarSnow
27th July, 2012 at 27/07/2012 21:44:21 -

So, I figured that placing quotes around the filepath might work. T'was a little tricky since the expression editor won't allow quotes around Apppath$ + "ip.bat", so I had to use the ASCII Character Object to convert from IndextoChar before and after the filepath, now it looks like this:

"ipconfig /all > "+IndexToChar( "ASCII Character Object", 34)+Apppath$+"ip.txt"+IndexToChar( "ASCII Character Object", 34)

The BAT file works, but here's the quirky thing... it works when I manually run it. When I try to execute it from MMF2, the batch file just doesn't run; like... at all. I've tried using MMF2's built in "Execute External Program" and it's File Object equivalent without success. Before I messed with the ASCII Character Object, I didn't have any trouble running the external batch file. What's the deal? o_O

I'm so confused.

EDIT: I think I *might* know what's causing the problem. I believe that when MMF2 runs the batch file, it executes it using command.exe which doesn't accept quoted filepaths, and when I run it manually, Windows uses cmd.exe which will allow quoted filepaths. After testing a bit, that was exactly the problem. I had to manually reference cmd.exe rather than command.exe then add a c/ switch and the path to my batch file.

I think I might be able to simplify this a bit and kill that bat file all together. I modified the command to:
CMD /C "ipconfig /all > "+IndexToChar( "ASCII Character Object", 34)+Apppath$+"ip.txt"+IndexToChar( "ASCII Character Object", 34)

Still works without a hitch. Awesome.

Edited by The_Antisony

 
ChrisD> Employer: Say, wanna see a magic trick?
ChrisD> Employee: Uhh… sure, boss.
ChrisD> Employer: Your job! It just disappeared! Pack your things and leave! Pretty good trick, huh?

The_Antisony

At least I'm not Circy

Registered
  01/07/2002
Points
  1341

VIP MemberStarSnow
28th July, 2012 at 28/07/2012 01:20:55 -

After about an hour of screwing around with the list object's "FindString" and "FindStringExact" functions, I finally trashed that idea and figured it out using Mid$. I kinda doubt anybody else would ever need to pull a MAC address, but I really hate it when a solution is found but not shared, so just in case, here it is:

You'll need the ASCII Character Object, the File Object, a String object, and a List Object.

Start of Frame ->
Special Conditions: Execute external program "cmd""/c "+"ipconfig /all > "+IndexToChar( "ASCII Character Object", 34)+Apppath$+"ip.txt"+IndexToChar( "ASCII Character Object", 34);

File Object: Apppath$ + "ip.txt" is a file AND Only one action when event loops ->
List Object: Load List File Apppath$+"ip.txt";
List Object: Set Current Line to 0;
StartLoop: findMAC List Nb Lines ("List Object") times;
://^^Probably not the best way to do it^^://

On loop "findMAC" AND Mid$(List Select$("List Object"),8,16) = "Physical Address" ->
String Object: Set alterable string to Right$(List Select$("List Object"),17);
Stop Loop: "findMAC";
://For my project, that's really all I need, so I destroy the List Object, then use the File Object to delete ip.txt://

On loop "findMAC" AND Mid$(List Select$("List Object"),8,16) <> "Physical Address" ->
List Object: Set Current Line List Select ("List Object") +1;

Nobody should care; but I think it's shexy.
I could have probably adapted the event scripting to pull a MAC from a second or third NIC too, but this is good enough for my project.

Edited by The_Antisony

 
ChrisD> Employer: Say, wanna see a magic trick?
ChrisD> Employee: Uhh… sure, boss.
ChrisD> Employer: Your job! It just disappeared! Pack your things and leave! Pretty good trick, huh?
   

Post Reply



 



Advertisement

Worth A Click