Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting the MAC Address

29 views
Skip to first unread message

Thomas M

unread,
Oct 18, 2002, 9:57:02 PM10/18/02
to
Here's a batch file that I created to return the MAC address.

----------
@echo off

::Write the IP information to a text file
ipconfig /all > %temp%\ipconfig.txt

::Get the MAC address from the text file
for /f "tokens=2 delims=:" %%a in ('find /n "Physical Address" %temp%
\ipconfig.txt') do set MAC=%%a

set MAC=%MAC:~1%

::Remove the temp file
del %Temp%\ipconfig.txt

Can anyone show me a better way to get the MAC address?
----------

--

Please reply to the newsgroup so that all may learn
from your wisdom.

--Tom

Ritchie

unread,
Oct 19, 2002, 5:02:04 AM10/19/02
to
"Thomas M" <mis...@hotmail.com> wrote in message news:MPG.181a69dc2...@News.CIS.DFN.DE...

> Here's a batch file that I created to return the MAC address.
>
> ----------
> @echo off
>
> ::Write the IP information to a text file
> ipconfig /all > %temp%\ipconfig.txt
>
> ::Get the MAC address from the text file
> for /f "tokens=2 delims=:" %%a in ('find /n "Physical Address" %temp%
> \ipconfig.txt') do set MAC=%%a
>
> set MAC=%MAC:~1%
>
> ::Remove the temp file
> del %Temp%\ipconfig.txt
>
> Can anyone show me a better way to get the MAC address?

Thomas,
I can't believe you've not already tried without the temp file, did you run
into some kind of problem?

for /f "tokens=3 delims=:. " %%a in (
'ipconfig /all^|find /i "physical address"'
) do set MAC=%%a

:: You might even get away with this...
for /f "tokens=3 delims=:. " %%a in ('ipconfig /all^|find "-"') do set MAC=%%a

--
Ritchie
Undo address for mail


Thomas M

unread,
Oct 21, 2002, 3:33:10 PM10/21/02
to
In article <3db12044$0$1285$cc9e...@news.dial.pipex.com>,
rit...@commanddoline.co.uk says...

I didn't try it without the text file because I wasn't aware of that
method. I borrowed my approach from another batch file that I have that
pulls the OS and service pack data from the registry. In that batch
file, the registry key is written to a text file, then the values are
pulled out of the text file. I wonder if your approach could be used
for that batch file too.

Ritchie

unread,
Oct 21, 2002, 4:17:19 PM10/21/02
to
> I didn't try it without the text file because I wasn't aware of that
> method. I borrowed my approach from another batch file that I have that
> pulls the OS and service pack data from the registry. In that batch
> file, the registry key is written to a text file, then the values are
> pulled out of the text file. I wonder if your approach could be used
> for that batch file too.

You were already using 'that' method, ie executing a command/program in
FOR /F statement and parsing StdOut. Regards reading the registry, if
you were exporting keys using regedit.exe then the temp file is required
as regedit.exe only writes to a file (even if the filename parameter is
CON).

You could use REG.EXE from the reskit, (or from a W2K CD [support tools])
as that writes to StdOut. Make sure you use Version 2.0 though, the
previous version has a few oversights.

Having said all that, you can 'cheat' if you have an NTFS volume - instead
of creating a temp file, append the Regedit output to the batchfile using
Alternate Data Streams. This example displays the SP level on NT4/W2K.

========================================================================
@echo off&setlocal ENABLEEXTENSIONS
set CV="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
regedit /e %~f0:reg %CV%
for /f "tokens=2 delims==" %%a in ('find "CSDVersion"^<%~f0:reg') do (
set SP=%%~na
)
echo/%SP%
type nul >%~f0:reg
========================================================================

Here's a thread about the subject:-
http://groups.google.co.uk/groups?threadm=80oth5%24sqb%241%40nnrp1.deja.com

If anyone has additional info, please do post.

Frank

unread,
Oct 21, 2002, 7:06:48 PM10/21/02
to
Ritchie <3db46188$0$1287$cc9e...@news.dial.pipex.com>...

^ ... if you were exporting keys using regedit.exe ... (even if
^ the filename parameter is CON).

Do you mean 'REGEDIT /e CON ...'? Doesn't work for me.


^ ... using Alternate Data Streams.

OH BOY!! A new toy! Thanks Ritchie! If I'd ever open up my web browser I'd
probably learn a few things. I'm amazed that I've never heard of Alternate
Data Streams before.

I'm only half way through one document I found on the topic but it seems to
me that these can be used for file notes. I wouldn't want to attach a note to
every file on my system but for certain directories a short description on
each file could be very useful. Then list the directory with a script that
will read the file notes as well.

Frank

Ritchie

unread,
Oct 22, 2002, 2:01:53 AM10/22/02
to
"Frank" <jnvqx...@aadhymgaipmwwcfw.com> wrote in message news:01c27956$924e2b60$0125250a@aadhymgaipmwwcfw...

> Ritchie <3db46188$0$1287$cc9e...@news.dial.pipex.com>...
>
> ^ ... if you were exporting keys using regedit.exe ... (even if
> ^ the filename parameter is CON).
>
> Do you mean 'REGEDIT /e CON ...'? Doesn't work for me.

Isn't that what I said? Didn't I also say that doesn't work? I must be
missing something

> ^ ... using Alternate Data Streams.
>
> OH BOY!! A new toy! Thanks Ritchie! If I'd ever open up my web browser I'd
> probably learn a few things. I'm amazed that I've never heard of Alternate
> Data Streams before.

Yer right! If you've never heard of 'em, then I'm a Dutchman.

> I'm only half way through one document I found on the topic but it seems to
> me that these can be used for file notes. I wouldn't want to attach a note to
> every file on my system but for certain directories a short description on
> each file could be very useful. Then list the directory with a script that
> will read the file notes as well.

Other uses include 'hiding' files, passwords?, and even executables. I guess
you could also mysteriously fill a hard drive (I first read about them in a
hacking book).

I believe there is still no tool to delete the stream once its been created,
anyone??? (it can be emptied with type >nul file::stream, but the stream
remains).

Please post any new info you find.

Frank

unread,
Oct 22, 2002, 6:41:03 AM10/22/02
to
Ritchie <3db4ea98$0$1287$cc9e...@news.dial.pipex.com>...

^ Yer right! If you've never heard of 'em, then I'm a Dutchman.

There's nothing wrong with being Dutch. I honestly never heard of alternate
streams before and this shouldn't be surprising: I haven't studied Computer
Science in school; I haven't taken any computer courses other than a Netware
Administrator course; I don't work in the computer industry; I rarely discuss
computer related topics outside of this newsgroup; and I rarely browse the
Web.


^ > I'm only half way through one document I found on the topic but it
^ > seems to me that these can be used for file notes.

They may not work very well as file notes. I attached a note to a text
document and verified that it was there, then I edited the document with a
text editor. When the text editor saved the modified document it destroyed
the link to the alternate stream and I had to recreate it.

^ Other uses include 'hiding' files, passwords?, and even executables.

Probably the most useful is what you've already shown us: temporary data
repositories for scripts. I'll probably be using this idea in the future.


^ I believe there is still no tool to delete the stream once its
^ been created, anyone???

Apparently not.


^ ... (it can be emptied with type >nul file::stream ...

And eliminated in this manner:

TYPE FileWithADS.txt > FileWithoutADS.txt
ERASE FileWithADS.txt


Frank

Michael Marquart

unread,
Oct 22, 2002, 1:25:15 PM10/22/02
to
On Mon, 21 Oct 2002 21:17:19 +0100, "Ritchie" <rit...@commanddoline.co.uk>
wrote:

Re: Alternate Data Streams

>Here's a thread about the subject:-
>http://groups.google.co.uk/groups?threadm=80oth5%24sqb%241%40nnrp1.deja.com
>
>If anyone has additional info, please do post.

Not sure if it's new but this is informative.

http://www.diamondcs.com.au/streams/streams.htm

Ritchie

unread,
Oct 23, 2002, 4:31:13 AM10/23/02
to
"Michael Marquart" <mi...@melbpc.org.au> wrote in message news:4d2brusmpoq1n9ngu...@4ax.com...

Thanks Michael,

Here are a few more links that might save anyone researching or developing
utils for Alternate Data Streams some time:-

a) http://patriot.net/~carvdawg/docs/dark_side.html


b) http://www.heysoft.de/nt/ntfs-ads.htm

c) http://www.microsoft.com/msj/defaultframe.asp?page=/msj/1198/ntfs/ntfs.htm&nav=/msj/1198/newnav.htm

Frank

unread,
Oct 23, 2002, 6:17:15 AM10/23/02
to
Ritchie <3db65e5a$0$1290$cc9e...@news.dial.pipex.com>...

^ Here are a few more links that might save anyone researching
^ or developing utils for Alternate Data Streams some time:-

Developing? Did you have something in mind? There are several utilities out
there that show the existence of alternate streams on files so I didn't
intend to make the utility I just wrote available to the public, but if you
have something in mind that the others are lacking then I could add that
feature and make it available.

The utility I wrote just prints a directory listing like this:

>ADS /d t*
505 t
11 t:FileNote
505 t.cmd
11 t.cmd:FileNote
501 tt.cmd
0 tempDir
30 tempDir:FileNote

Which reminds me of the file note idea. Since alternate data streams can be
attached to directories and since directories aren't overwritten by file
editors, a directory would be a much better location for file notes. My
single attempt at using MORE to read alternate streams on directories failed
but FINDSTR doesn't seem to have trouble with them. For example, where
C:\temp has a file note for each file in that directory named after the file:

Set DIR=C:\temp
Set File=*
For %%a in (%Dir%\%File%) Do (
For /F "delims=" %%b in ('FindStr $^<%Dir%:%%~na') Do Echo/%%a %%b
)


Frank

Ritchie

unread,
Oct 23, 2002, 8:38:33 AM10/23/02
to
"Frank" <spygq...@wqwjbudajolbvfhb.com> wrote in message news:01c27a7d$63de2a00$0125250a@wqwjbudajolbvfhb...

> Ritchie <3db65e5a$0$1290$cc9e...@news.dial.pipex.com>...
>
> ^ Here are a few more links that might save anyone researching
> ^ or developing utils for Alternate Data Streams some time:-
>
> Developing? Did you have something in mind? There are several utilities out

Someone. You! I figured you'd be writing a util that does something with ADS

> a directory would be a much better location for file notes.

Reading through the links I posted earlier, there was mention of directories
supporting ADS - I hadn't realised that - but it does make perfect sense. I
guess it wouldn't be so simple to delete a stream from a folder.

> single attempt at using MORE to read alternate streams on directories failed

To prevent MORE pausing after each screen, I've used this on W2K:-

more<file:stream>con

But maybe you had different issue.

Just curious, did you notice whether the streams have attributes like
regular files (archive, date, time etc)?

Frank

unread,
Oct 23, 2002, 10:13:43 AM10/23/02
to
Ritchie <3db6984d$0$1290$cc9e...@news.dial.pipex.com>...

^ more<file:stream>con
^
^ But maybe you had different issue.

It's a memory access error when MORE is given an alternate data stream on a
directory. I've only tried it on one directory but it failed to read it
several times.

Echo/Old backup of RunProcess.txt>zDir:FileNote

FAILS:
MORE<zDir:FileNote

SUCCEEDS:
FINDSTR $<zDir:FileNote


^ Just curious, did you notice whether the streams have attributes like
^ regular files (archive, date, time etc)?

They don't. Alternate data streams are part of the file so they share the
same attributes, extended attributes, and security information. Alternate
data streams are also read the same way as extended attributes and security
information when the file is backed up to a tape device, which is how all
programs that look for alternate data streams find them. The API function is
BackupRead(). This gave be an idea for deleting them: use BackupRead() to
read the file and simultaneously use BackupWrite() to write it back to the
same file, skipping all alternate data sections. I may try this after I
finish my FileInfo.exe (ADS enabled) program and a "list special folders.exe"
program. I wish I could get paid for all this work!

Frank

0 new messages