Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61825

Re: [newbie] trying socket as a replacement for nc

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=0529c492a=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.038
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'subject:: [': 0.04; '"""': 0.07; 'socket': 0.07; 'advance': 0.07; 'string': 0.09; 'back.': 0.09; 'implements': 0.09; 'subject:trying': 0.09; 'python': 0.11; 'adapter': 0.16; 'measurement': 0.16; 'port)': 0.16; 'module': 0.19; 'subject:] ': 0.20; 'import': 0.22; 'print': 0.22; 'header :In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'tried': 0.27; 'host': 0.29; "doesn't": 0.30; "skip:' 10": 0.31; 'jean': 0.31; 'anyone': 0.31; 'allows': 0.31; 'linux': 0.33; 'url:python': 0.33; '-----': 0.33; 'skip:# 10': 0.33; 'could': 0.34; 'thanks': 0.36; 'url:org': 0.36; 'thank': 0.38; 'e.g.': 0.38; 'url:library': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'system.': 0.39; 'how': 0.40; 'tell': 0.60; 'equipment': 0.61; 'skip:t 30': 0.61; 'simple': 0.61; 'you.': 0.62; 'information': 0.63; 'such': 0.63; 'received:194': 0.64; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'sample': 0.67; 'notice:': 0.67; 'person,': 0.68; 'privileged.': 0.69; 'disclose': 0.74; 'medium.': 0.91; 'instrument': 0.93
X-IronPort-AV E=Sophos;i="4.95,479,1384297200"; d="scan'208";a="2240098"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Fri, 13 Dec 2013 16:35:31 +0100 (CET)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To Jean Dubois <jeandubois314@gmail.com>, python-list@python.org
In-Reply-To <efae1b3c-c9c5-4ef4-8e94-7fbe8716ab53@googlegroups.com>
Subject Re: [newbie] trying socket as a replacement for nc
MIME-Version 1.0
X-Mailer Zimbra 7.2.4_GA_2900 (ZimbraWebClient - GC31 (Win)/7.2.4_GA_2900)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4072.1386948939.18130.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386948939 news.xs4all.nl 2895 [2001:888:2000:d::a6]:39835
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61825

Show key headers only | View raw


----- Original Message -----
> I have an ethernet-rs232 adapter which allows me to connect to a
> measurement instrument by means of netcat on a linux system.
> e.g. entering nc 10.128.59.63 7000
> allows me to enter e.g.
> *IDN?
> after which I get an identification string of the measurement
> instrument back.
> I thought I could accomplish the same using the python module
> "socket"
> and tried out the sample program below which doesn't work however:
> #!/usr/bin/env python
> 
> """
> A simple echo client
> """
> import socket
> host = '10.128.59.63'
> port = 7000
> size = 10
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> s.connect((host,port))
> s.send('*IDN?')
> data = s.recv(size)
> s.close()
> print 'Received:', data
> 
> Can anyone here tell me how to do it properly?
> thanks in advance
> jean

Such equipment often implements a telnet protocol. Have use try using the telnetlib module ?
http://docs.python.org/2/library/telnetlib.html

t = Telnet(host, port)
t.write('*IDN?')
print t.read_until('Whateverprompt')
# you can use read_very_eager also

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [newbie] trying socket as a replacement for nc Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-12-13 16:35 +0100
  Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-14 05:33 -0800
    Re: [newbie] trying socket as a replacement for nc Dan Stromberg <drsalists@gmail.com> - 2013-12-14 17:03 -0800
      Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-15 07:35 -0800
        Re: [newbie] trying socket as a replacement for nc Chris Angelico <rosuav@gmail.com> - 2013-12-16 02:50 +1100
        Re: [newbie] trying socket as a replacement for nc Dan Stromberg <drsalists@gmail.com> - 2013-12-15 13:14 -0800

csiph-web