How can I open a TCP port in Raspberry Pi - tcp

I have a Raspberry pi and I would like open a TCP port on it for example port : 11000
I tried to find a command in the internet for doing this but I could not.
I would be thankful if some body help me in this matter
thanks !

I would suggest digging into the ins and outs of networking since there are many options and you will need to be aware of the security implications with opening up your ports to the world. IP addresses are scanned every minute of every hour of every day so be very careful.
This is a simple example using netcat (nc) on the Bash shell. Below are two (2) nodes; my Raspberry Pi 2, and one of my Ubuntu servers; which is on the same network. Both nodes don't have any open ports except for SSH.
However, you'll see how easy it is to pass information from the Ubuntu server to the Pi without authentication.
So... the Pi opens (listens) on port 11000 and sends incoming data into file capture.this. Then Ubuntu server echos a message to the Pi's LAN IP address at port 11000.
pi#raspberrypi:~ $ nc -lp 11000 > capture.this
david#ubuntuserver002:~$ echo "Hey, What's up Cuz!" | nc 10.100.71.141 11000
pi#raspberrypi:~ $ cat capture.this
Hey, What's up Cuz\!

Related

How to simulate the exact same network traffic that was previoulsy recorded?

On Unix, how to simulate the exact same network traffic that was previously recorded?
I have a LAN made of 2 machines:
A local PC with interface eth0 and IP 192.168.1.1. On this PC runs a code C that listens to eth0, grab UDP packets and produce a result with them.
A remote hardware with IP 192.168.1.10. The hardware needs an initialization step (configuration, handshake, acknowledgment) and needs to be maintained active with a heartbeat. As long as the hardware is active, it sends data (grabbed by the local PC at the other end). All the different communications are done through different ports (see picture).
On the local PC, I plug the remote running HW, run tcpdump -i eth0 -w dump.pcap & (running in background), and just after that I run the code C that uses UDP packets received from HW (in parallel tcpdump is running). This produces a result R1 on the local PC: R1 is valid and can be post-processed.
Now, after the record dump.pcap is done, I let the remote HW running (otherwise eth0 dies - ip a does no more associate an IP to eth0), I run tcpreplay -K --intf1=eth0 dump.pcap & (running in background), and just after that I re-run the code C that uses UDP packets received from tcpreplay running in parallel (at least, that's my understanding of what should occur). The traces when C runs looks correct (initialization OK, no error, running / receiving looks OK). Unfortunately, C produces another result R2... Which is different from R1: R2 is invalid and can not even be post-processed?! The size of R2 is about the size of R1 but seems to be filled with zero/uninitialized data.
Is it possible to simulate the exact same traffic that the one that was previously recorded? If yes, what did I miss or what do I do wrong?
Note: I use a bash script to run tcpdump and C just one after the other when recording, and run tcpreplay and C just one after the other when replaying (trying to do things the same ways with similar delays as much as possible).

Bridging two ports with netcat/socat

I need to get data from a ModBus device (modbus slave) over TCP but this device has to be exposed as a TCP client (it eats much less from the battery in this case). It means that both machines have to connect to the third one as TCP clients an I have to build a bridge between two ports, something like this
[modbus slave] -> [4444:bridge:5555] <- [modbus master]
I did try it with the netcat on a bridge machine
$ /bin/netcat -lk 5555 | /bin/netcat -lk 4444
It works the half way: I can connect to 4444 with my slave and to 5555 with my master, and traffic flows from master to slave. However, I do not see any traffic in the opposite direction. How do I build a two-way bridge in this case?
Thanks a lot in advance!
You can run 2 netcat instances with a fifo like this:
# mkfifo fifo
# nc -l -p 4444 < fifo | nc -l -p 5555 > fifo
You can also do it using just socat.
# socat TCP4-LISTEN:4444 TCP4-LISTEN:5555
On a side note, I would imagine running a client consumes more power (which needs to keep on connecting) than server (which only waits for incoming connection). Maybe there is some other design consideration that I missed.

Can't access device through network

I'm trying to interface a device with python.
The device is connected to another machine in the same network (the university network) and I know it's Port number.
I can access the device from the PC where it is plugged with the following code:
dev = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dev.connect(('137.195.53.140',51019))
where '137.195.53.140' is the PC ip, and 51019 is the port number.
However, if I try the same from another machine, ipython gets stack at the command "dev.connect(('137.195.53.140',51019))", and when I abort the evaluation and then look at "dev" I get this:
<socket.socket fd=15, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('137.195.204.85', 50393)>
where '137.195.204.85' is the IP of the machine I'm using, and the port number I've no idea.
Since ssh works with no problem within this network, I thought that my approach for accessing the device would have worked as well.
Does anyone have any clue for this? I'm sorry if I haven't been clear, but I know absolutely nothing of networking (and not very much of Python either tbh).
There's couple of things to consider:
Your university network ports
Your device's opened ports
Your network might have the 51019 port blocked. Also, ssh uses port 22 to make it's connection. Every port is a world, so there's the chance that just because 22 is open, it doesn't mean that another is. School networks usually have a pretty rigid policy on port closing for security and blocking unwanted sites too.
You can test your device access by pinging it as
$ ping 137.195.204.85
If that works, then you can go trying different ports

IPv6 over BLE Using BLE dongles

Recently I have been experimenting with IPv6 over BLE. I started by using a Raspberry PI, a Nordic semiconductor nrf51 device and sample code supplied by Nordic. I had no problems getting a COAP server up and running on the Nordic device and was able to access the server from the Raspberry PI using a COAP client.
My next step was to try and send data between two Raspberry PIs, using IPv6 over BLE.
To do this at the slave end:
sudo su
echo 1> /sys/kernel/debug/bluetooth/6lowpan_enable
hciconfig hci0 leadv
So at this stage the slave is advertising
At the master end
sudo su
echo 1> /sys/kernel/debug/bluetooth/6lowpan_enable
hcitool lescan
Make note of slave MAC address
echo "connect MAC address 1" > /sys/kernel/debug/bluetooth/6lowpan_control
ifconfig
Confirm existence of bt* interface
hcitool con
To confirm connection
ping6 -I bt* ff02::1
The above works for a short time and is quite unstable. Next I would like to send data back and forth from slave and master. At the master end, I have an interface which can be used to send data, but at the slave end I have nothing. I guess I need to set up a bt interface at the slave end, so data can be sent back and forth.
Any suggestions or recommendations would be appreciated.

OpenMPI: Multiple Ethernet Interfaces Failure

I wanted to setup a 3-node ring network, each connects to the other 2 using 2 Ethernet ports directly without a switch/router.
The interface configurations looks like this:
I've used ifconfig on each node to configure each port, and made sure I can ssh from each node to the other 2 nodes.
But a simple ring_c example doesn't work... So I turn on --mca btl_base_verbose 30, I could see that node1 was trying to use 23.0.0.2 (linke between node2 and 3) to get to node2 though there is a direct link to node 2.
The output log is like:
[node1:01828] btl: tcp: attempting to connect() to [[19529,1],1]
address 23.0.0.2 on port 1024
[[19529,1],0][btl_tcp_endpoint.c:606:mca_btl_tcp_endpoint_start_connect]
from node1 to: node2 Unable to connect to the peer 23.0.0.2 on port
4: Network is unreachable
I've read the following posts and FAQs but still couldn't understand this kind of behavior.
How does Open MPI know which IP addresses are routable to each other in Open MPI 1.3 (and beyond)?
How do I tell Open MPI which IP interfaces / networks to use?
Open MPI User's Mailing List Archives
Any pointers would be appreciated! Thanks in advance!
My open-mpi info:
Open MPI: 1.0.0.22
Open RTE: 1.0.0.22
OPAL: 1.0.0.22
MPI API: 2.1
Best,
Shang

Resources