analitics

Pages

Sunday, January 8, 2023

Python 3.7.9 : The sunpy python package - part 001.

In the past, I have written several small tutorials related to this Python package. Now I have some news related to the sunpy python package:
  • HelioviewerClient is deprecated;
  • The Helioviewer Project now maintains a Python Wrapper called hvpy.
  • sunpy users are encouraged to upgrade parfive python package;
  • the sunpy.database deprecation;
  • the sample data files provided through sunpy.data.sample are now downloaded individually on demand;
  • SunPy is tested against Python 2.7, 3.5, and 3.6.;
  • SunPy no longer supports Python 3.4.;
  • easy to extract data values from a GenericMap along a curve specified by a set of coordinates using the new sunpy.map.extract_along_coord function;
  • has a new make_heliographic_header() function that simplifies creating map headers that span the whole solar surface in Carrington or Stonyhurst coordinates;
  • aiaprep is now deprecated;
  • ... and more on the official website.
I install this python package on the Windows OS with the pip tool:
pip install "sunpy[all] -U"
You can install extra available options: [asdf], [dask], [database], [image], [jpeg2000], [map], [net], [timeseries], [visualization].
You can see the version of this python package with this source code:
 import sunpy
print(sunpy.__version__)
3.1.8
I tested this package with this simple source code:
from matplotlib import pyplot as plt
import sunpy.map
import sunpy.data.sample  
sunpyAIA = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE) 
sunpyAIA.plot()
plt.colorbar()
plt.show()
The instrument is AIA and the measurement is 171, see more on this online tool named helioviewer.
After I run I got this image:

Python 3.11.0 : The scapy python module - part 003.

Scapy is a powerful interactive packet manipulation program. It is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, match requests and replies, and much more. It can easily handle most classical tasks like scanning, tracerouting, probing, unit tests, attacks or network discovery (it can replace hping, 85% of nmap, arpspoof, arp-sk, arping, tcpdump, tshark, p0f, etc.). It also performs very well at a lot of other specific tasks that most other tools can’t handle, like sending invalid frames, injecting your own 802.11 frames, combining technics (VLAN hopping+ARP cache poisoning, VOIP decoding on WEP encrypted channel, …), etc.
First, you need to install it with pip tool: pip install scapy --user.
I used with WinPcap from this webpage, but you will see the recomandation is to use Npcap.
#!/usr/bin/env python3
import os
print(os.sys.path)
from scapy.all import *

def mysniff(interface):
    sniff(iface=interface, store=False, prn=process_sniffed_packet)

def process_sniffed_packet(packet):
    pyperclip.copy(str(packet))
    print(packet)

mysniff("Realtek PCIe GbE Family Controller")
The running result is something like this:
...
WARNING: WinPcap is now deprecated (not maintained). Please use Npcap instead
Ether / IP / TCP 104.244.42.2:https > 192.168.0.143:55478 PA / Raw
Ether / IP / TCP 192.168.0.143:55478 > 104.244.42.2:https PA / Raw
Ether / IP / TCP 192.168.0.143:55478 > 104.244.42.2:https PA / Raw
Ether / IP / TCP 104.244.42.2:https > 192.168.0.143:55478 A / Padding
Ether / IP / TCP 104.244.42.2:https > 192.168.0.143:55478 A / Padding
Ether / ARP who has 192.168.0.1 says 192.168.0.206 / Padding
...