So, I have been playing around with my Raspberry Pi Zero and tshark in SSH when I thought, why not make a script that did all the work for me? So I used nano and created a python file called script.py and inside I wrote:
import os
os.system('sudo tshark -i eth0 -w capture-output.pcap')
I then did /python script.py which started off well but when it got to capturing on eth0 it stopped and said:
tshark: Couldn't create child process: cannot allocate memory.
Sorry about my python newbieness but please help because I am designing a Hak5 Packet squrriel clone. Thank you anyway and I look forward to hearing from you soon, Thomas
EDIT
So, I have kind of resolved this issue by doing sudo -i then creating a sh file instead of a python one but I prefer the python language so would really like to know what was happening. Thank you very much, Thomas
Related
I am doing a project where I have to install the jetson nano board to a train and detect the gps location of it. But I cannot find a proper solution to include gps module to the jetson board. Please it would be great if there is anyone who can help me with it.
Thanks in advance!
So from what I know exactly the best way to do so would be to get an actual gps module for the jetson nano (do not know which exact model but I think we can go with the popular 4g model) and an example of one is https://www.waveshare.com/sim7600g-h-4g-for-jetson-nano.htm but you can also do something that isn't so accurate. Little bash script, hope it helps.
So first I would ssh into your device, you can run ifconfig to get a little bit of an idea. It by default would be wlan0 for the wirless module and eth0 for the wired connection.
Let's make the file
touch nanoloc.sh && sudo chmod +x nanoloc.sh
Then just run this little script here:
#!/bin/bash
#define what shell we want to use above
format="json" #xml or json
user="" #add your current user
nano_ip="$(curl ifconfig.co)"
ip_locaddr=https://freegeoip.app/$format/$nano_ip
data_file=/mnt/c/Users/$user/output.$format #change this to your expected path
touch data_file #make the file
echo data_file #make sure we have the right one
curl "$ip_locaddr" > data_file #write it out
cat data_file #let's see what it says
Now you should be able to see what it outputs when you run ./nanoloc.sh
Hope this helps, also am running this from WSL (you can see from the path where it's mounted) and tested on Linux.
The idea was to use my RBP as a baby monitor that would stream over the network so that I could watch from any computer/TV at home.
1.To begin with, I was trying to stream a video from my raspberry pi to be access from another PC using VLC Network Stream.
It worked using this command line :
raspivid -o - -t 0 -hf -w 800 -h 400 -fps 24 |cvlc -vvv stream:///dev/stdin --sout'#standard{access=http,mux=ts,dst=:8160}' :demux=h264
After that i wanted it to start from a python program.
Done using that simple program:
from subprocess import call
call(["raspivid -o - -t 0 -hf -w 800 -h 400 -fps 24 |cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8160}' :demux=h264"])
Now it needed to launch the python program at startup. So I created a .desktop file in autostart:
mkdir /home/pi/.config/autostart
nano /home/pi/.config/autostart/autostartCamStream.desktop
autostartCamStream.desktop :
[Desktop Entry]
Type=Application
Name=AutostartCam
Exec=/usr/bin/python3 /home/pi/startCamStream.py
Everything is doing exactly what it is supposed to do! On reboot, the startCamStream.py start streaming and I can access it over my VLC player on my PC on port 8160.
But the problem is that on the Raspberry pi, the stream is full screen and I cant close it or do anything else... Ive try CRTL+Q, ATL+F4 etc. Nothing is working (I cant even see a terminal, the recording seems to be in front of every other programs) Before the autostart, I was closing the stream using CTRL-C since it was running in a terminal.
As I only have basic knowledge in linux environment, I was wondering if anyone has a pretty obvious solution I wouldn't know about... Thank you !
just adding -n to the raspivid command solved the problem.
-n stops the video being previewed.
In the company I work at we're trying to allow file sharing on all the mac's so me and my IT team are able to see their files remotely. But I'm not very familiar with macs. Is there a way to script this process, preferably in Python? (If not python, then applescript)
Googling around, it seems to me that you can turn on SMB file sharing for a folder with this set of command lines, which you can run from Python or AppleScript as you see fit:
sudo /usr/sbin/sharing -a /path/to/sharedFolder
sudo /usr/sbin/sharing -e sharedFolder -s 001
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist
The first line creates a sharing record, the second adds the SMB flag to the record, and the third starts the file server.
The site where I saw the last command had a second command:
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist EnabledServices -array disk
I don't know what precisely this line does — if anything — though it may ensure that SMB is restarted after a reboot(?)
N.B.: I'm not sure when the sharing command line tool was added to the system. It may be recent, so if you are running older systems you should check to make sure it's available. See man sharing for examples and options.
I have made a dreadful error and am looking for your help!
I have set up my raspberry pi to run a python script at start up by editing the rc.local file. This would be fine except I have written my script to reboot the raspberry pi when it exits. Now I am stuck in an infinite loop and I can't edit anything. Every time my script ends it reboots the pi and starts again!
My program uses Pygame as a GUI and I have a Raspberry Pi 3 running the NOOBS OS that came with it. If you need anymore info please ask.
Any help stopping my script so I can access the pi without losing any data will be greatly appreciated.
Edit - What an amazing community. Thank you everyone for sharing your knowledge and time. I was in a bit of a panic and you all came to my assistance really quick. If you are reading this because you are in a similar predicament I found Ben's answer was the quickest and easiest solution, but if that doesn't work for you I think FrostedCookies' idea would be the next thing to try.
Probably the easiest way is to take out the SD card from your Pi, mount the SD filesystem onto another computer running linux and edit your rc.local script from there to remove the infinite boot loop. You can also backup your data that way incase something goes wrong.
I'm not sure if this will work (I don't have a Pi right now), but if you can't access a terminal normally while the script is running, try the keyboard shortcut Ctrl+Alt+F1 to open one, then type sudo pkill python to kill the script (this will also kill any other python processes on your machine). Then use a terminal text editor (vi or nano perhaps) to edit your rc.local file so this doesn't happen again.
It's a Raspberry Pi solution rather than a Python/unix one, but you could plug the SD card into another computer, mount it, and modify the script to stop the reboot cycle.
More information about editing the files from your Pi's SD card on another computer here: https://raspberrypi.stackexchange.com/questions/9515/how-to-access-the-rpi-root-ext4-file-system-by-inserting-sd-card-into-a-differen
I'd firstly turn it off and on again..
If it wont help
ps aux | grep -i python
killall python - youll probably need to tweak the killall command with the python script name instead or in addition to "python"
I'm trying to do a live capture with pyshark, but it wants to run tshark using sudo. I'm not sure how to run sudo out of python. The github thread states: "you can create a 'script' that just runs "sudo tshark" and tell pyshark to run that instead of tshark."
Buuuuut I'm not too sure how to do that. I was looking at Using sudo with Python script
but again not sure how to "run that instead of tshark"
Has anyone done this? Can anyone advise?
Bit more info here: If you're an admin user, you don' t need sudo to run "tshark -c 100 -i en0". If you "sudo chmod 777 /dev/bpf*" that works for things like Carnivore in Processing, but does zip all for Pyshark. Trying to edit Startup items to give you read access is moot on OSX because Yosemite tossed it.
Other info: https://apple.stackexchange.com/questions/138694/what-is-access-bpf-group
I'm really starting to think something is just up w/ PyShark itself.
Thanks
Don't use sudo to run Wireshark. Instead, configure your user account to be able to use Wireshark without root access. Detailed instructions are here: https://ask.wireshark.org/questions/7976/wireshark-setup-linux-for-nonroot-user
WELP. turns out it was just because I hadn't used 'en0' Marking this as solved. HA.