all ip addresses of machines in the local network

Discussion in 'Python' started by damacy, Aug 24, 2006.

  1. damacy

    damacy Guest

    hi, there. i have a problem writing a program which can obtain ip
    addresses of machines running in the same local network.

    say, there are 4 machines present in the network; [a], , [c] and [d]
    and if i run my program on [a], it should be able to find "host names"
    and "ip addresses" of the other machines; , [c] and [d]?

    i have read some threads posted on this group, however, they only work
    for localhost, not the entire network.

    any hints if possible?

    thanks for your time.

    regards, damacy
    damacy, Aug 24, 2006
    #1
    1. Advertising

  2. damacy

    Sandra-24 Guest

    damacy wrote:
    > hi, there. i have a problem writing a program which can obtain ip
    > addresses of machines running in the same local network.
    >
    > say, there are 4 machines present in the network; [a], , [c] and [d]
    > and if i run my program on [a], it should be able to find "host names"
    > and "ip addresses" of the other machines; , [c] and [d]?
    >
    > i have read some threads posted on this group, however, they only work
    > for localhost, not the entire network.
    >
    > any hints if possible?
    >
    > thanks for your time.
    >
    > regards, damacy


    What is this for? Some kind of high availablity server setup? I don't
    know anything that would be useful to you, but I am curious, and maybe
    it will clarify your intentions for others.

    -Sandra
    Sandra-24, Aug 24, 2006
    #2
    1. Advertising

  3. damacy

    damacy Guest

    hi, sandra.

    no, it's not as complicated as that. all i want to do is to load a
    database onto different machines residing in the same network. i hope
    there is a way doing it. or perhaps i have a poor understanding of how
    networks work.

    regards, damacy

    Sandra-24 wrote:
    > damacy wrote:
    > > hi, there. i have a problem writing a program which can obtain ip
    > > addresses of machines running in the same local network.
    > >
    > > say, there are 4 machines present in the network; [a], , [c] and [d]
    > > and if i run my program on [a], it should be able to find "host names"
    > > and "ip addresses" of the other machines; , [c] and [d]?
    > >
    > > i have read some threads posted on this group, however, they only work
    > > for localhost, not the entire network.
    > >
    > > any hints if possible?
    > >
    > > thanks for your time.
    > >
    > > regards, damacy

    >
    > What is this for? Some kind of high availablity server setup? I don't
    > know anything that would be useful to you, but I am curious, and maybe
    > it will clarify your intentions for others.
    >
    > -Sandra
    damacy, Aug 24, 2006
    #3
  4. damacy

    John Bokma Guest

    "damacy" <> wrote:

    > hi, there. i have a problem writing a program which can obtain ip
    > addresses of machines running in the same local network.
    >
    > say, there are 4 machines present in the network; [a], , [c] and [d]
    > and if i run my program on [a], it should be able to find "host names"
    > and "ip addresses" of the other machines; , [c] and [d]?
    >
    > i have read some threads posted on this group, however, they only work
    > for localhost, not the entire network.
    >
    > any hints if possible?


    google for nmap, don't reinvent the wheel.


    --
    John MexIT: http://johnbokma.com/mexit/
    personal page: http://johnbokma.com/
    Experienced programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
    John Bokma, Aug 24, 2006
    #4
  5. damacy

    mbstevens Guest

    On Wed, 23 Aug 2006 21:46:21 -0700, damacy wrote:

    > hi, sandra.
    >
    > no, it's not as complicated as that. all i want to do is to load a
    > database onto different machines residing in the same network. i hope
    > there is a way doing it. or perhaps i have a poor understanding of how
    > networks work.


    It would not be 'as complicated as that' if we knew the kind of
    network you are on -- NFS, Samba, Windows, some hybred network,
    SSH, FTP, telnet, remote X, remote desktops? Every service has its
    own way of doing things.
    mbstevens, Aug 24, 2006
    #5
  6. damacy

    John Bokma Guest

    "damacy" <> wrote:

    > hi, sandra.


    If you reply like is common on Usenet, there is no need to address
    someone, since the attribution line is just there:

    Sandra-24 wrote:
    ^^^^^^^^^^^^^^^

    Google for top posting, and read why it's generally considered bad.

    > no, it's not as complicated as that. all i want to do is to load a
    > database onto different machines residing in the same network.


    if they are all in the xx.yy.zz.ii range, with ii the only number that
    varies, you could ping each ii with a short time out. No reply = nothing
    on it (unless pings are blocked).

    --
    John MexIT: http://johnbokma.com/mexit/
    personal page: http://johnbokma.com/
    Experienced programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
    John Bokma, Aug 24, 2006
    #6
  7. damacy

    Amit Khemka Guest

    On 23 Aug 2006 21:46:21 -0700, damacy <> wrote:
    > hi, sandra.
    >
    > no, it's not as complicated as that. all i want to do is to load a
    > database onto different machines residing in the same network. i hope
    > there is a way doing it. or perhaps i have a poor understanding of how
    > networks work.
    >


    I expect that you would know the IP range for your network. Then you
    can simply 'ping' each IP in the range to find wether its alive.
    Moreover by your description I guess you would actually want to find
    all machines in your network that run a particular network service, to
    allow you to "distribute the database". In such case you can use
    "nmap" with -p option, to find all the machines which are listening on
    the particular port.

    hth,
    amit.


    ----
    Amit Khemka -- onyomo.com
    Home Page: www.cse.iitd.ernet.in/~csd00377
    Endless the world's turn, endless the sun's Spinning, Endless the quest;
    I turn again, back to my own beginning, And here, find rest.
    Amit Khemka, Aug 24, 2006
    #7
  8. damacy

    Amit Khemka Guest

    On 8/24/06, Amit Khemka <> wrote:
    > On 23 Aug 2006 21:46:21 -0700, damacy <> wrote:
    > > hi, sandra.
    > >
    > > no, it's not as complicated as that. all i want to do is to load a
    > > database onto different machines residing in the same network. i hope
    > > there is a way doing it. or perhaps i have a poor understanding of how
    > > networks work.
    > >

    >
    > I expect that you would know the IP range for your network. Then you
    > can simply 'ping' each IP in the range to find wether its alive.
    > Moreover by your description I guess you would actually want to find
    > all machines in your network that run a particular network service, to
    > allow you to "distribute the database". In such case you can use
    > "nmap" with -p option, to find all the machines which are listening on
    > the particular port.
    >
    > hth,
    > amit.

    It seems that I am not too busy, so here is a code which may work with
    a few tweaks here and there:
    _________________________________________________________________________
    import os
    # base and range of the ip addresses
    baseIP = "10.0.0."
    r = 6
    interestingPort = 22 # port that you want to scan
    myIPs = []

    for i in range(r):
    ip = baseIP+str(i) # It may need some customization for your case
    print "scanning: %s" %(ip)
    for output in os.popen("nmap %s -p %s" %(ip,
    interestingPort)).readlines():
    if output.__contains__('%s/tcp open'
    %interestingPort): # i guess it would be tcp
    myIPs.append(ip)
    __________________________________________________________________________
    print myIPs


    hth,
    amit.
    --
    ----
    Amit Khemka -- onyomo.com
    Home Page: www.cse.iitd.ernet.in/~csd00377
    Endless the world's turn, endless the sun's Spinning, Endless the quest;
    I turn again, back to my own beginning, And here, find rest.
    Amit Khemka, Aug 24, 2006
    #8
  9. damacy

    tobiah Guest

    I am a member of another list that has at least one member
    who has lost his vision, and reads his news with a speech
    generator. It is terribly inconvenient for him to follow
    a thread full of 'bottom postings', as he is then forced to
    sit through the previous message contents again and again
    in search of the new content.

    > Google for top posting, and read why it's generally considered bad.
    >


    --
    Posted via a free Usenet account from http://www.teranews.com
    tobiah, Aug 24, 2006
    #9
  10. damacy

    John Bokma Guest

    tobiah <> wrote:

    > I am a member of another list that has at least one member
    > who has lost his vision, and reads his news with a speech
    > generator. It is terribly inconvenient for him to follow
    > a thread full of 'bottom postings', as he is then forced to
    > sit through the previous message contents again and again
    > in search of the new content.


    Yes, that's why it's also recommended to *remove all lines you're not
    replying to*. A full quote is always annoying (unless it's really needed
    to get some context, which is in general rare).

    Not only people with a vision problem will be thankful for that. Like I
    recommended to *read* on top posting, instead of repeating myths that are
    made up by people who are ignorant.

    Simple recipe:
    http://johnbokma.com/mexit/2006/04/11/how-to-reply.html

    I am sure that people with a vision problem who jump into the thread
    prefer a small context over listening "upside down" to get some context, I
    mean:

    A: top posting
    Q: what is the most annoying thing on Usenet

    Now imagine that Q is quote after quote after qoute because a hand ful of
    lazy clueless bastards want to save time.

    --
    John MexIT: http://johnbokma.com/mexit/
    personal page: http://johnbokma.com/
    Experienced programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
    John Bokma, Aug 24, 2006
    #10
  11. damacy

    Chaz Ginger Guest

    When is a subclass not right?

    I was writing some code that used someone else class as a subclass. He
    wrote me to tell me that using his class as a subclass was incorrect. I
    am wondering under what conditions, if ever, does a class using a
    subclass not work.

    Here is an example. For instance the original class might look like:

    class A :
    def __init__(self,arg) :
    self.foo = arg
    def bar(self) :
    return self.foo


    And I defined a class B1 which looked like:


    class B1(A);
    def __init__(self,a1,a2) :
    self.c = a1
    A.__init__(self,ag)


    He said I should use it this way:

    class B2:
    def __init__(self,a1,a2):
    self.c = a1
    self.t = A(a2)

    def bar(self) :
    self.t.bar()


    Other than the obvious difference of B2 having an attribute 't', I can't
    see any other obvious differences. Is there something I am missing?

    TIA
    Chaz
    Chaz Ginger, Aug 24, 2006
    #11
  12. damacy

    Tim Chase Guest

    Re: blindness and top vs. bottom posting (was "all ip addresses ofmachines in the local network")

    > I am a member of another list that has at least one member
    > who has lost his vision, and reads his news with a speech
    > generator. It is terribly inconvenient for him to follow
    > a thread full of 'bottom postings', as he is then forced to
    > sit through the previous message contents again and again
    > in search of the new content.


    I'm involved on the Blind Linux users (Blinux) list, and they
    seem to have no problem bottom-posting.

    There are a variety of tools for converting bottom-posting into
    more readable formats. If you want to suppress comments, a
    quality MUA can suppress them. Or you can pipe them through
    sed/grep/whatever and strip out all lines beginning with a
    greater-than sign. Or, use the search functionality in the
    screen-reader to skip ahead to the next line until you get to one
    that doesn't begin with a greater-than sign. Some text-display
    areas even allow you to use searching to move the cursor. E.g.
    if reading a mail in mutt in a console, you can open it in vim
    and search for "^[^>]" which will move the cursor to the next
    line that doesn't begin with a greater-than sign. Quite usable
    from within yasr ("yet another screen reader").

    Inspired by a problem discussed on the Blinux list, I've also
    created a python tool for converting standard quoting notation
    (using greater-than signs) into a more TTS-friendly
    (text-to-speech) format:

    http://www.redhat.com/archives/blinux-list/2006-June/msg00012.html
    http://www.redhat.com/archives/blinux-list/2006-June/msg00015.html
    http://www.redhat.com/archives/blinux-list/2006-June/msg00016.html

    Thus, there are tools for blind/visually-impared folks that can
    make it easier for them to correspond using the standards the
    rest of the world uses. Even among blind users, there's often a
    division between those that use Braille terminals and those that
    use TTS. Those using Braille tend to fall in with the rest of
    the internet, preferring bottom-posting. Those using TTS aren't
    quite so fond of having their own content regurgitated back to
    them. However, judicial pruning of quoted contend can ease that
    problem.

    Thus, there are plenty of tools to help BVI folks operate under
    the standard of bottom-posting.

    -tkc
    Tim Chase, Aug 24, 2006
    #12
  13. Re: When is a subclass not right?

    please don't hit reply to arbitrary messages when you're posting new
    messages; it messes up the message threading.

    Chaz Ginger wrote:

    > I was writing some code that used someone else class as a subclass. He
    > wrote me to tell me that using his class as a subclass was incorrect. I
    > am wondering under what conditions, if ever, does a class using a
    > subclass not work.


    your terminology is confused: if you inherit from another class, *your*
    class is the subclass, while the class you inherit from is known as a
    "base class" or "super class".

    a subclass will share the instance namespace with the base class, which
    means, among other things, that you may accidentally override internal
    attributes and methods, and thus break the base class.

    and even if it appears to work now, it may break when you upgrade the
    base class. or when you end up in a code path that you haven't tested
    before.

    </F>
    Fredrik Lundh, Aug 24, 2006
    #13
  14. damacy

    Chaz Ginger Guest

    Re: When is a subclass not right?

    Fredrik Lundh wrote:
    > please don't hit reply to arbitrary messages when you're posting new
    > messages; it messes up the message threading.
    >
    > Chaz Ginger wrote:
    >
    >> I was writing some code that used someone else class as a subclass. He
    >> wrote me to tell me that using his class as a subclass was incorrect.
    >> I am wondering under what conditions, if ever, does a class using a
    >> subclass not work.

    >
    > your terminology is confused: if you inherit from another class, *your*
    > class is the subclass, while the class you inherit from is known as a
    > "base class" or "super class".
    >
    > a subclass will share the instance namespace with the base class, which
    > means, among other things, that you may accidentally override internal
    > attributes and methods, and thus break the base class.
    >
    > and even if it appears to work now, it may break when you upgrade the
    > base class. or when you end up in a code path that you haven't tested
    > before.
    >
    > </F>
    >

    Sorry for the threading screw up. I thought I had just hit the write button.

    I understand when my class overrides the super class. But that would
    just be "normal" class related things. I was wondering if there was
    something more subtle I am missing in Python class handling.

    Chaz
    Chaz Ginger, Aug 24, 2006
    #14
  15. damacy

    Chaz Ginger Guest

    Re: When is a subclass not right?

    Fredrik Lundh wrote:
    > please don't hit reply to arbitrary messages when you're posting new
    > messages; it messes up the message threading.
    >
    > Chaz Ginger wrote:
    >
    >> I was writing some code that used someone else class as a subclass. He
    >> wrote me to tell me that using his class as a subclass was incorrect.
    >> I am wondering under what conditions, if ever, does a class using a
    >> subclass not work.

    >
    > your terminology is confused: if you inherit from another class, *your*
    > class is the subclass, while the class you inherit from is known as a
    > "base class" or "super class".
    >
    > a subclass will share the instance namespace with the base class, which
    > means, among other things, that you may accidentally override internal
    > attributes and methods, and thus break the base class.
    >
    > and even if it appears to work now, it may break when you upgrade the
    > base class. or when you end up in a code path that you haven't tested
    > before.
    >
    > </F>
    >

    Sorry for the threading screw up. I thought I had just hit the write button.

    I understand when my class overrides the super class. But that would
    just be "normal" class related things. I was wondering if there was
    something more subtle I am missing in Python class handling.

    Chaz
    Chaz Ginger, Aug 24, 2006
    #15
  16. Re: When is a subclass not right?

    At Thursday 24/8/2006 16:23, Chaz Ginger wrote:

    >I was writing some code that used someone else class as a subclass. He
    >wrote me to tell me that using his class as a subclass was incorrect. I
    >am wondering under what conditions, if ever, does a class using a
    >subclass not work.
    >
    >class B1(A);
    > def __init__(self,a1,a2) :
    > self.c = a1
    > A.__init__(self,ag)
    >
    >class B2:
    > def __init__(self,a1,a2):
    > self.c = a1
    > self.t = A(a2)
    >
    > def bar(self) :
    > self.t.bar()
    >
    >Other than the obvious difference of B2 having an attribute 't', I can't
    >see any other obvious differences. Is there something I am missing?


    Look any OO book for the difference between 'inheritance' and
    'delegation'. In short, you should inherit when B 'is an' A (a Car is
    a Vehicle), and delegate/compose in other cases (a Car has an Engine;
    or more precisely, a Car instance has an Engine instance).


    Gabriel Genellina
    Softlab SRL



    p5.vert.ukl.yahoo.com uncompressed Thu Aug 24 19:27:05 GMT 2006


    __________________________________________________
    Preguntá. Respondé. Descubrí.
    Todo lo que querías saber, y lo que ni imaginabas,
    está en Yahoo! Respuestas (Beta).
    ¡Probalo ya!
    http://www.yahoo.com.ar/respuestas
    Gabriel Genellina, Aug 24, 2006
    #16
  17. damacy

    Carl Banks Guest

    Re: When is a subclass not right?

    Chaz Ginger wrote:
    > I was writing some code that used someone else class as a subclass. He
    > wrote me to tell me that using his class as a subclass was incorrect. I
    > am wondering under what conditions, if ever, does a class using a
    > subclass not work.

    [snip]
    > He said I should use it this way:
    >
    > class B2:
    > def __init__(self,a1,a2):
    > self.c = a1
    > self.t = A(a2)
    >
    > def bar(self) :
    > self.t.bar()
    >
    > Other than the obvious difference of B2 having an attribute 't', I can't
    > see any other obvious differences. Is there something I am missing?


    I think it's kind of a fine point. In my own code I've had cases where
    I've switched from subclass to attribute and back over the development,
    and vice versa. I think there are many cases where it's preferable to
    use an attribute, but not really wrong to subclass (and vice versa).

    The classical advice in choosing whether to subclass or or use
    attribute is whether its more an an "is a" or "has a" relationship. If
    it's more natural to say B is an A, then subclass. If it's more
    natural to say B has an A, then use an attribute. But that's only a
    rule of thumb.

    I personally find another question helpful. If it's reasonable that B
    could have more than one of A, regardless if it actually does, use an
    attribute. If it's unreasonable, subclass. Again, rule of thumb.


    Carl Banks
    Carl Banks, Aug 24, 2006
    #17
  18. damacy

    Chaz Ginger Guest

    Re: When is a subclass not right?

    Gabriel Genellina wrote:
    > At Thursday 24/8/2006 16:23, Chaz Ginger wrote:
    >
    >> I was writing some code that used someone else class as a subclass. He
    >> wrote me to tell me that using his class as a subclass was incorrect. I
    >> am wondering under what conditions, if ever, does a class using a
    >> subclass not work.
    >>
    >> class B1(A);
    >> def __init__(self,a1,a2) :
    >> self.c = a1
    >> A.__init__(self,ag)
    >>
    >> class B2:
    >> def __init__(self,a1,a2):
    >> self.c = a1
    >> self.t = A(a2)
    >>
    >> def bar(self) :
    >> self.t.bar()
    >>
    >> Other than the obvious difference of B2 having an attribute 't', I can't
    >> see any other obvious differences. Is there something I am missing?

    >
    > Look any OO book for the difference between 'inheritance' and
    > 'delegation'. In short, you should inherit when B 'is an' A (a Car is a
    > Vehicle), and delegate/compose in other cases (a Car has an Engine; or
    > more precisely, a Car instance has an Engine instance).
    >
    >
    > Gabriel Genellina
    > Softlab SRL
    >
    >
    > p5.vert.ukl.yahoo.com uncompressed Thu Aug 24 19:27:05 GMT 2006
    >
    > __________________________________________________ Preguntá. Respondé.
    > Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en
    > Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas


    That is merely a logical use of OO after all when would a car and an
    orange be the same?

    I was wondering more about the mechanics of Python: when does B1 show
    different characteristics than B2 (forgoing the obvious simple things,
    like 't' above).

    Chaz
    Chaz Ginger, Aug 24, 2006
    #18
  19. damacy

    Chaz Ginger Guest

    Re: When is a subclass not right?

    Gabriel Genellina wrote:
    > At Thursday 24/8/2006 16:23, Chaz Ginger wrote:
    >
    >> I was writing some code that used someone else class as a subclass. He
    >> wrote me to tell me that using his class as a subclass was incorrect. I
    >> am wondering under what conditions, if ever, does a class using a
    >> subclass not work.
    >>
    >> class B1(A);
    >> def __init__(self,a1,a2) :
    >> self.c = a1
    >> A.__init__(self,ag)
    >>
    >> class B2:
    >> def __init__(self,a1,a2):
    >> self.c = a1
    >> self.t = A(a2)
    >>
    >> def bar(self) :
    >> self.t.bar()
    >>
    >> Other than the obvious difference of B2 having an attribute 't', I can't
    >> see any other obvious differences. Is there something I am missing?

    >
    > Look any OO book for the difference between 'inheritance' and
    > 'delegation'. In short, you should inherit when B 'is an' A (a Car is a
    > Vehicle), and delegate/compose in other cases (a Car has an Engine; or
    > more precisely, a Car instance has an Engine instance).
    >
    >
    > Gabriel Genellina
    > Softlab SRL
    >
    >
    > p5.vert.ukl.yahoo.com uncompressed Thu Aug 24 19:27:05 GMT 2006
    >
    > __________________________________________________ Preguntá. Respondé.
    > Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en
    > Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas


    That is merely a logical use of OO after all when would a car and an
    orange be the same?

    I was wondering more about the mechanics of Python: when does B1 show
    different characteristics than B2 (forgoing the obvious simple things,
    like 't' above).

    Chaz
    Chaz Ginger, Aug 24, 2006
    #19
  20. damacy

    Ben Finney Guest

    Re: blindness and top vs. bottom posting

    Tim Chase <> writes:

    > > I am a member of another list that has at least one member who has
    > > lost his vision, and reads his news with a speech generator. It
    > > is terribly inconvenient for him to follow a thread full of
    > > 'bottom postings', as he is then forced to sit through the
    > > previous message contents again and again in search of the new
    > > content.

    >
    > I'm involved on the Blind Linux users (Blinux) list, and they seem
    > to have no problem bottom-posting.
    >
    > There are a variety of tools for converting bottom-posting into more
    > readable formats. If you want to suppress comments, a quality MUA
    > can suppress them.


    The parent poster is complaining about a straw man. As they point out,
    "bottom posting" is almost as bad as top posting. Both practices leave
    the entire content of quoted material intact, regardless of which
    parts are relevant.

    The correct solution to both top posting *and* bottom posting is
    "interleaved posting", but more importantly to trim away everything
    except the quoted material necessary for giving context to one's
    response. This is of even greater assistance to the blind, who then
    have just the necessary context to understand the current message.

    <URL:http://en.wikipedia.org/wiki/Top_posting>

    --
    \ "We are not gonna be great; we are not gonna be amazing; we are |
    `\ gonna be *amazingly* amazing!" -- Zaphod Beeblebrox, _The |
    _o__) Hitch-Hiker's Guide To The Galaxy_, Douglas Adams |
    Ben Finney
    Ben Finney, Aug 24, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: How to find Fax machines on the network

    Kevin Spencer, Aug 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    354
    Kevin Spencer
    Aug 20, 2004
  2. Simon Brown
    Replies:
    0
    Views:
    345
    Simon Brown
    May 6, 2004
  3. namespace1
    Replies:
    3
    Views:
    882
  4. John [H2O]
    Replies:
    0
    Views:
    226
    John [H2O]
    Oct 28, 2008
  5. Alessio Pace
    Replies:
    0
    Views:
    623
    Alessio Pace
    Jan 7, 2009
Loading...

Share This Page