How to find MAC address and uids?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel T.

    #1

    How to find MAC address and uids?

    I'm writing a script for work and to finnish it, I need two bits of
    information which I'm having trouble finding.

    1) How can I programatically find the MAC address of the machine? Is it
    stored in a file I can look into? (MacOS X)

    2) If I have a user name in a string how do I get his UID?

    Thanks to anyone that can help.
  • Marcin Jurczuk

    #2
    Re: How to find MAC address and uids?

    On 2004-11-10, Daniel T. <postmaster@ear thlink.net> wrote:
    [color=blue]
    > 1) How can I programatically find the MAC address of the machine? Is it
    > stored in a file I can look into? (MacOS X)[/color]
    What is syntax of this file ??
    [color=blue]
    > 2) If I have a user name in a string how do I get his UID?[/color]
    [color=blue][color=green][color=darkred]
    >>> import pwd
    >>> pwd.getpwnam('s pock')[/color][/color][/color]
    ('spock', 'x', 100, 101, '', '/export/home/spock', '/bin/bash')[color=blue][color=green][color=darkred]
    >>> pwd.getpwnam('s pock')[2][/color][/color][/color]
    100[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]


    --
    Marcin Jurczuk, NIC-HDL: MJ1679-RIPE

    Comment

    • Marcin Jurczuk

      #3
      Re: How to find MAC address and uids?

      On 2004-11-10, Marcin Jurczuk <mj-usunto@tkb.pl> wrote:[color=blue]
      > On 2004-11-10, Daniel T. <postmaster@ear thlink.net> wrote:
      >[color=green]
      >> 1) How can I programatically find the MAC address of the machine? Is it
      >> stored in a file I can look into? (MacOS X)[/color]
      > What is syntax of this file ??[/color]
      My Mistake :)
      If you have access to /sbin/ifconfig (if MacOS X is FreeBSD based it should
      be in /sbin) you can use something like this:[color=blue][color=green][color=darkred]
      >>> import os
      >>> a=os.popen('/sbin/ifconfig bge0|grep ether').read(). replace('\n','' ).split()[1]
      >>> print a[/color][/color][/color]
      00:30:84:b3:b3: 3a[color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]

      Important - replace bge0 your card name ...
      [color=blue]
      >[color=green]
      >> 2) If I have a user name in a string how do I get his UID?[/color]
      >[color=green][color=darkred]
      >>>> import pwd
      >>>> pwd.getpwnam('s pock')[/color][/color]
      > ('spock', 'x', 100, 101, '', '/export/home/spock', '/bin/bash')[color=green][color=darkred]
      >>>> pwd.getpwnam('s pock')[2][/color][/color]
      > 100[color=green][color=darkred]
      >>>>[/color][/color]
      >
      >[/color]


      --
      Marcin Jurczuk, NIC-HDL: MJ1679-RIPE

      Comment

      • James Weatherley

        #4
        Re: How to find MAC address and uids?

        In article <postmaster-718ADE.06591510 112004@news1.ea st.earthlink.ne t>,
        postmaster@eart hlink.net says...[color=blue]
        > I'm writing a script for work and to finnish it, I need two bits of
        > information which I'm having trouble finding.
        >
        > 1) How can I programatically find the MAC address of the machine? Is it
        > stored in a file I can look into? (MacOS X)[/color]

        $ ifconfig | grep ether | awk {'print $2'}
        Note that there may be 0, 1 or many MAC addresses.
        [color=blue]
        > 2) If I have a user name in a string how do I get his UID?[/color]

        This gets the uid for 'james':
        $ nireport . /users name uid | grep james | awk '{print $2}'

        Comment

        • Mike Hall

          #5
          Re: How to find MAC address and uids?

          Daniel T. wrote:
          [color=blue]
          >2) If I have a user name in a string how do I get his UID?[/color]

          "man getpwnam" might help you find an answer.


          Comment

          Working...