Selamat datang, ini adalah artikel awal menginstal FastAPI sebagai pembuka sebelum kita mengenal lebih jauh bagaimana membuat aplikasi dengan Python dan FastAPI. Pada artikel ini kita akan mengenal bagaimana memasang dan mengkonfigurasi FastAPI. Pada akhir dari artikel, kalian sudah dapat membuat sebuah Rest API sederhana berbasis FastAPI.
Category: Python
Mengenal dpkt (Bagian 1): Membaca Berkas pcap
Tulisan ringkas berikut disarikan dari beberapa sumber yang ada. Salah satunya dari blog milik Jon Oberheide. Karena penelitian saya berkaitan dengan keamanan jaringan maka analisis dari network traffic menjadi sebuah keharusan. dpkt adalah pustaka yang dibuat oleh Dug Song. Beliau seingat saya salah satu anggota dari monkey.org dan sudah membuat beberapa perangkat lunak yang berkaitan dengan jaringan. Di artikel ini saya coba paparkan sedikit cara menggunakan pustaka dpkt secara ringkas. Dokumentasi dan cara sudah banyak bertebaran dalam bahasa Inggris sedangkan untuk bahasa Indonesia belum ada atau masih jarang silakan cek di duckduckgo. Selanjutnya saya mencoba berkontribusi dalam bahasa Indonesia.
Continue reading “Mengenal dpkt (Bagian 1): Membaca Berkas pcap”
Resolve pip for Python 3.4 on FreeBSD
This just newbie problem. I had FreeBSD version 10.2 server. The default installation for python is python 2.7. I had script with python 3 as the interpreter so I install the python 3 from the pkg using
How To Parse Website (2)
My late post How to Parse Website Part 1 has shown you the basic website parsing. Next in this post I will show you more. Open your python command line again then try parse our last website. Here is the result from website I’ve been parse accessed via browser.
How To Parse Website (1)
In this post I will guide you step by step to parse website. I chose python, though. Each language has its own style but I prefer python because I know its strength and its resilient. Maybe some other time I can try another language as an example. This post will not show you how to install python.
Playing With Raspberry Pi (Part 1) : How To Install an OS to Raspi
I know maybe it’s already too late for discussing raspberry pi (raspi) but hey, it’s my first time touching this little one and playing with it. I’m not gonna write the history behind or anything related but i’m gonna share my experience. Actually this is not my own raspi, my friend gave me. He has a project related with raspi and python, some kind of robot project. It’s because he doesn’t have python knowledge so he asked me to do some research with his raspi. So first we have to know what kind of model, how much memory and so on. I’m in hurry so my first target is to install raspi (yeay!) using operating system that available on the site. How about the models?, how much memory this raspi have ?. We’ll talk about it later.
Okay my choice is Arch Linux. Why ?, Smaller size than Raspbian. Actually there is another one like RISC OS but i’m afraid some packages are unavailable to download or modify or there is too much dependencies but the choice is yours. The other reason is because I have slow internet connection :). That’s all. Remember, raspi using SD Card for installation. So prepare your SD Card, Image OS (choose your own OS and download from http://www.raspberrypi.org/downloads/) and Win32 Disk Imager (download from http://sourceforge.net/projects/win32diskimager/).
Ok here is my raspi from Element 14. Figure 1 in the box and Figure 2.
Figure 1. Raspberry Pi from element 14
Figure 2. Raspberry Pi
Installing OS to raspi is very simple. First, we have to format SD Card and injecting the image. Insert the SD Card into your notebook (assuming your notebook has SD Card slot) then open the win32diskimager like this Figure 3.
Browse your downloaded image and don’t forget to point into the right device. BEWARE !, WRONG POINTING DEVICE can ruined your notebook drive. After that push the “Write” button and wait until the process is done. If the format successfull we can forward to the next step. Insert the SD Card into the back of your raspi like Figure 4 here.
There are 2 ways to display your raspi on a monitor or TV. We can use RCA cable to connect to TV or we can use HDMI connector. Because I don’t have any HDMI cable so I choose RCA cable. The RCA cable are the most common cable so I hope you can find it in the general store or any store that sell electrical appliances. The RCA cable is like this in Figure 5.
Figure 5. RCA Cable
The cable has 3 connectors, i’m using the yellow one. Plug in into your TV (find the the yellow hole in front or back). Prepare your USB keyboard and mouse to configure. I only use USB keyboard though :). Okay the last one we plug the power cord. And here is the alarmpi (Arch Linux Arm) in Figure 6.
Figure 6. RCA Cable for display
Login to the shell using root and password root. Tada !, congratulation. That’s all for now.
Figure 7. Login shell
Mengenal AppGyver – Bagian 2
Automatic Backup MySQL Using Python
Here is a script I create to make backup MySQL Database. Check this out.
#!/usr/bin/env python
# PyBack.py v1.1
# MySQL Backup Script
# Author Andrey Ferriyan
# Package MySQL
# SubPackage MySQL Backup Script
# License GNU/GPL
# Description Backup MySQL With Cron Method
from ftplib import FTP
import subprocess
import tarfile
# User Database, Password Database, Host Database, Port Database
USERDB='andrey'
PASSDB='blablapass'
HOSTDB='localhost'
PORTDB='3306'
# Database pada mysql yang akan di backup
ARR_DB = ['wordpress']
# Hostname / IP Address, FTPLOGIN = user FTP, FTPPASS = password FTP
FTPHOST=''
FTPLOGIN=''
FTPPASS=''
class PyBack(object):
def __init__(self):
self.USERDB=USERDB
self.PASSDB=PASSDB
self.HOSTDB=HOSTDB
self.ARR_DB=ARR_DB
self.FTPHOST=FTPHOST
self.FTPLOGIN=FTPLOGIN
self.FTPPASS=FTPPASS
self.PORTDB=PORTDB
def backup(self):
subprocess.call("/bin/rm -rf /tmp/backup",shell=True)
subprocess.call("/bin/mkdir /tmp/backup",shell=True)
for x in self.ARR_DB:
subprocess.call("mysqldump -h "+self.HOSTDB+" --databases "+x+" --user="+self.USERDB+" --password="+self.PASSDB+" -P "+self.PORTDB+" -R > /tmp/backup/"+x+".sql",shell=True)
def grouping(self):
tar = tarfile.open("/tmp/backup.tar.bz2","w:bz2")
tar.add("/tmp/backup/")
tar.close()
def transfer(self):
ftp = FTP(self.FTPHOST)
ftp.login(self.FTPLOGIN,self.FTPPASS)
ftp.storbinary("STOR /tmp/backup.tar.bz2",open("/tmp/backup.tar.bz2","rb"),1024)
if __name__ == '__main__':
pyback = PyBack()
pyback.backup()
pyback.grouping()
pyback.transfer()
Carefull with Python Syntax, especially the indentation. You have to modify the script to match with your environment. Then you can install the script in the cron system. Just try it first, don’t forget to setup a FTP Server or a local FTP Server for testing it. Have a nice try!
Connecting To Oracle Database Using cx_Oracle On Python
Mungkin ini pernah ditulis dulu cuma hilang ya sudah tidak ada salahnya aku tulis ulang. Posisi sementara hardware yang sedang kugunakan masih sama :
1. IBM Thinkpad Z61t Intel Centrino Duo
2. RAM 1 GB
Kebutuhan software:
- cx_Oracle (http://sourceforge.net/projects/cx-oracle/files/)
- Oracle Database tentunya dalam hal ini saya masih menggunakan versi 10.2.0
- Python 2.6
- Sabily / Ubuntu 10.4.1
Langkah-langkah:
- Dengan menggunakan user oracle, download cx_Oracle dari situsnya
- Extract file tar.gz tersebut
- Jangan lupa ketika akan menginstall diusahakan environment ORACLE_HOME sudah siap. Bisa dicek dengan mengetikkan kode berikut di bash shell anda. “echo $ORACLE_HOME” (tanpa petik). Jika belum segera diset dengan cara yang simpel juga pada bash shell anda dengan user oracle ketikkan “export ORACLE_HOME=/u01/app/oracle/product/10.2.0” (tanpa petik) dalam hal ini angka 10.2.0 sesuaikan dengan installasi Oracle anda
- Masuk ke direktori hasil extract file tar.gz cx_Oracle, ketikkan “cd cx_Oracle-5.0” (tanpa petik)
- Ketikkan berikut di bash shell anda, “python setup.py build” (tanpa petik)
- Setelah itu akan muncul proses kompilasi. Setelah selesai ketikkan “python setup.py install” (tanpa petik). Maka file cx_Oracle akan berhasil dikompilasi namun belum tersimpan di folder library python (pada /usr/local/lib/python2.6/dist-packages)
- Setelah berhasil silahkan dicoba koneksi dengan cara yang tertera pada video youtube berikut ini
Bagi yang ingin mengetahui bagaimana cara installasi Oracle 10g pada Ubuntu bisa merujuk pada artikelku sebelumnya How To Install Oracle 10g Release 2 On Ubuntu 10.04.1 Lucid Lynx 32 bit. Atau bagi yang menggunakan Oracle 11g bisa merujuk pada artikel ini How To Install Oracle 11g Release 2 On Oracle Enterprise Linux 5.5
** PERHATIAN **
Perlu diingat bahwa untuk sementara ini Ubuntu tidak di support oleh Oracle, oleh karena itu jika anda menggunakannya untuk production server maka lebih baik gunakan OS yang memang direkomendasikan oleh Oracle seperti Oracle Enterprise Linux atau CentOS atau RedHat.
Banner Grabber
Refresh otak bentar dari koding php. Buat web scanner atau banner grabber untuk mengambil data web server tertentu kemudian menyimpan hasilnya. Bukan murni scanning karena yang scan adalah netcraft. Untuk hasil datanya belum dirapikan karena ini juga cuma iseng, qe3. Berikut adalah kodenya
#!/usr/bin/env python
# myscanner.py
# Web Scanner Using Python
# Andrey Ferriyan
#
from BeautifulSoup import BeautifulSoup
import urllib
import os
import getopt
import sys
class MyScanner(object):
def __init__(self,url_victim):
self.url_victim = url_victim
self.gabung = "http://toolbar.netcraft.com/site_report?url=http://" + self.url_victim
def BeginScan(self):
self.scan = urllib.urlopen(self.gabung)
self.sup = BeautifulSoup(self.scan)
def Remove(self):
self.remove1 = self.sup.find('div',id='nav')
self.remove1.replaceWith("")
self.remove2 = self.sup.find('div',id='header')
self.remove2.replaceWith("")
self.dipercantik = self.sup.prettify()
def ResultFile(self):
self.folder = "result/"+self.url_victim
os.makedirs(self.folder)
self.fileresult = self.folder + '/result.html'
self.result = open(self.fileresult,'w+')
self.result.write(self.dipercantik)
self.result.close()
def Usage():
usage = '''
000-=====II=====II=====II=====II=====-000
00-= Web Scanner Using Python =-00
00-= Author : Andrey Ferriyan =-00
00-= =-00
000-=====II=====II=====II=====II=====-000
command : myscanner.py [option]
[option]:
-h / --help : help
-u / --url= : url
'''
print usage
if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], "hu:", ["help", "url="])
except getopt.GetoptError, err:
print str(err)
Usage()
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
Usage()
sys.exit()
elif o in ("-u","--url"):
my = MyScanner(a)
my.BeginScan()
my.Remove()
my.ResultFile()
else:
print "Kesalahan tidak tertangani"
File kecil ini membutuhkan Sup Indah dalam menjalankan aksinya. Btw, disarankan hanya yang tahu python yang boleh mencoba :). Selamat mencoba.