Posts by Ed S • 2,057 points
164 posts
-
1
votes0
answers51
viewsQ: Are tuples really immutable in Python?
t = (1,2,[4,6]) t is a tuple. If we do: t[2][0]="e" we shall have: (1, 2, ['e', 6]) Now the tuple t is (1, 2, ['e', 6]) We didn’t change the tuple? Be it s= "stackoverflow" It is not possible to do,…
-
0
votes2
answers75
viewsQ: Program that gives a secret number using bisection search
Create a program that gives a secret number using bisection search ! The user thinks of an integer between 0 (inclusive) and 100 (not included). The computer, using bisection search, gives a guess…
-
3
votes3
answers713
viewsQ: Print the largest substring of s where the letters occur in alphabetical order
Be a string with all lowercase characters. Write a program that prints the largest substring of s in which the letters occur in alphabetical order. For example: s = 'azcbobobegghakl' The program…
-
1
votes1
answer168
viewsQ: Program to convert mp3 using multiprocessing module is looping
import subprocess from multiprocessing import Process, Lock def ConverteMusica(a,lock): input_file_fmt = '{}.mp3' output_file_fmt = a for x in range(1, 5): subprocess.call(['ffmpeg', '-i',…
-
0
votes0
answers124
viewsQ: Program uses the threading module but I didn’t notice any parallelism in the execution. What’s wrong?
I made a script to decrease the quality of some mp3, calling the ffmpeg program through the subprocess module. I added Threads thinking of doing the process in parallel to multiple files at the same…
-
1
votes1
answer68
viewsQ: Code review: Threaded server to handle multiple clients
The server with Threading: import socket from threading import Thread def Servidor(): servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ip = "0.0.0.0" porta = 8884 servidor.bind((ip,…
-
0
votes0
answers118
viewsQ: Error trying to access ftp.debian.org using Python script: "Oserror: [Errno 101] Network is unreachable"
The script: import os from getpass import getpass #nao ecoa o que digita na tela! from ftplib import FTP # Variavél que determina se devemos usar o modo ativo # para FTP nonpassive = False # Nome do…
-
2
votes2
answers1256
viewsQ: Client and server programming: How to achieve numerous data exchanges per client and multiple clients simultaneously?
The client: from socket import * serverHost = 'localhost' serverPort = 50007 # Menssagem a ser mandada codificada em bytes menssagem = [b'Ola mundo da internet!'] # Criamos o socket e o conectamos…
-
0
votes0
answers41
viewsQ: I understand a parallel execution using _thread. Is there any more pythonic way to write the same code?
import _thread def filho(tid): print('Ola da thread', tid) def pai(): i = 0 while True: i += 1 _thread.start_new_thread(filho, (i,)) if input() == 'q': break pai() Is there any more pythonic way to…
-
2
votes2
answers1322
viewsQ: I understand a parallel run using Fork. How does Fork work?
import os def filho(): print('Ola do filho', os.getpid()) os._exit(0) def pai(): while True: newpid = os.fork()# fornece ID para um novo processo! if newpid == 0: filho() else: print('Ola do pai',…
-
0
votes1
answer479
viewsQ: How to write a calendar in alphabetical order of Names using Python Ordereddict?
Nomes = [] Telefones = [] Endereços = [] Emails = [] Agenda = {"Nome": Nomes,"Telefone":Telefones,"Endereço":Endereços, "Email": Emails} entrada = "" print("Bem-vindo a nossa Agenda!!!!!") while…
-
1
votes1
answer174
viewsQ: Generating functions: What are the advantages of using them?
Generating function: def geraQuadrados(n): for i in range(n): yield i**2 for i in geraQuadrados(5): print(i) no generating function: def novosQuadrados(n): l = [] for i in range(n): l.append(i**2)…
-
11
votes2
answers872
viewsQ: Program to simulate the anniversary paradox
In probability theory, the anniversary paradox states that given a group of 23 (or more) randomly chosen people, the chance that two people will have the same birthday date is more than 50%. For 57…
-
0
votes2
answers477
viewsA: How to access a private attribute in a class?
class Banco(object): __total =10000 TaxaReserva = 0.1 __reservaExigida = __total*TaxaReserva def podeFazerEmprestimo(self,valor): if self.__saldo >= 1000: return True def MudaTotal(self,valor):…
-
0
votes2
answers942
viewsA: How to write an alphabetical agenda of Names, if the dictionary structure has no order?
Nomes = [] Telefones = [] Endereços = [] Emails = [] Agenda = {"Nome": Nomes,"Telefone":Telefones,"Endereço":Endereços, "Email": Emails} entrada = "" print("Bem-vindo a nossa Agenda!!!!!") while…
-
0
votes2
answers477
viewsQ: How to access a private attribute in a class?
Write a program of banks you own: Uma classe Banco com os atributos - private total - public TaxaReserva - private reservaExigida E métodos - public podeFazerEmprestimo(valor) --> bool - public…
-
0
votes2
answers942
viewsQ: How to write an alphabetical agenda of Names, if the dictionary structure has no order?
Write a program that receives as many entries as the user wants and then create a new contact for each entry (Name, Phone, Address, Email), and finally prints, in alphabetical order, the contact…
-
1
votes1
answer153
viewsQ: Program to pick up on a web page events
source code here too: https://pastebin.com/DesqWJfY Objective: to catch events in http://www.bhaktiyogapura.com/2018/03/calendario-vaisnava-marco-2018/ Each month, the URL changes only the fine, for…
-
0
votes1
answer66
viewsQ: importing a file containing a function I wrote: no global variable
Constroimatriz.py file: """ Escreva uma função que recebe um inteiro m e outro n e com isso constrói uma matriz mxn """ matrix = [] def main(): m = int(input("Digite o número de linhas da matriz:…
-
1
votes2
answers116
viewsQ: Sorting algorithm not working!
""" Arrange the elements of a list in ascending order """ #ordenação bolha #L = [5,3,1,2,4] L = [7,4,3,12,8] x = 0 while x < (len(L) -1): if L[x] > L[x+1]: L[x],L[x+1] = L[x+1],L[x] x += 1…
-
-1
votes1
answer244
viewsQ: Code Review: Program that simulates the "door game": either you win a car or a goat!
Write a program to simulate the door game. Make a program that has the output as the following: Hello, welcome to our program! Let’s see if you will win a car or not! Choose one door: 3 You chose…
-
0
votes1
answer668
viewsQ: Approximation of the cosine function using the first n terms of a series
Data x real and n natural, calculate an approximation to cos x through n first terms of the following series: cos x = 1/1 - (x**2)/2! + (x**4)/4! - (x**6)/6! + ... + ((-1)**k)*(x**2k)/((2k)!) My…
-
1
votes1
answer1889
viewsQ: Print in ascending order the natural first n which are multiples of i or j or both
Data n and two positive integers i and j different from 0, print in ascending order the first natural n s which are multiples of i or of j and or both. Example: For n = 6 , i = 2 and j = 3 the…
-
0
votes2
answers1691
viewsQ: Algorithm to determine prime numbers between 2 and N. What is wrong?
n = int(input("Digite N: ")) lista =[] divisores =[] for i in range(2, n+1): for j in range(1,n+1): if i>=j: if i%j ==0: divisores.append(j) print("divisores",divisores) if len(divisores) ==2:…
-
1
votes1
answer507
viewsQ: Calculation of the maximum value for an expression of natural numbers using Python
Natural data m and n determine, among all pairs of natural numbers (x,y) such that x < m and y < n, a pair for which the value of the expression x*y - x**2 + y is maximum and also calculates…
-
1
votes2
answers107
viewsA: Estimating the response time of a server using Python or regex
Can solve using a free program: Response Time Viewer for Wireshark: http://www.solarwinds.com/free-tools/response-time-viewer-for-wireshark It provides, among other things, application and network…
-
3
votes1
answer474
viewsQ: Probabilistic Considerations on the Calculation of Shannon Entropy in a Network Traffic
Probabilistic Considerations on the Calculation of Shannon Entropy in a Network Traffic I have a dump file (CAP format) of a network traffic capture made with Debian tcpdump. Until a certain time,…
-
0
votes1
answer3728
viewsQ: Logarithmic Scale Graph with Python
Initially I created a Values X tempo (Unix Time) chart with the following code: # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import matplotlib.dates as dates from datetime import…
-
1
votes2
answers107
viewsQ: Estimating the response time of a server using Python or regex
I created a virtualized environment with an Apache server (running in Debian) and several attacking machines running Debian as well. Vmware Workstation was used. Server IP: 192.168.91.5 I have dump…
-
0
votes1
answer1394
viewsQ: How to improve a bar graph whose values are very close in Python?
I am drawing the bar graph using the following Python code: # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import matplotlib.dates as dates from datetime import datetime, timedelta x = [] y…
-
1
votes1
answer848
viewsQ: Display only hours, minutes and seconds on a graph whose input is in Unix time
Be the Python code that generates a bar graph: # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import matplotlib.dates as dates from datetime import datetime, timedelta x = [] y = [] with…
-
2
votes0
answers201
viewsQ: Counting the number of connections per IP to a web server on port 80. Is regex correct?
I would like to count the number of connections per IP per second (at port 80) to a web server whose IP is 192.168.1.216. The input for the count is a network dump file in the PCAP (.pcap file)…
-
9
votes1
answer597
viewsQ: How to calculate Shannon entropy based on HTTP header
Shannon’s entropy is given by the formula: Where Ti will be the data extracted from my network dump (dump.pcap). The end of an HTTP header on a normal connection is marked by \r\n\r\n: Example of an…
-
6
votes1
answer705
viewsQ: How to extract information from an HTTP header with Python?
We know that in the HTTP protocol, the end of the header is indicated by "\r\n\r\n". Example: It may be that, for some reason, the customer does not send the "\r\n\r\n" to the server (could be an…
-
-2
votes1
answer452
viewsQ: Bar graph generated with Python has become unreadable. How to improve it? How to work with a dataset of more than 1 million lines?
Friends, The following bar chart was generated (the first column of datasets is UNIX time): The Python code (version 3.5) used was the following: # -*- coding: utf-8 -*- import matplotlib.pyplot as…
-
1
votes1
answer200
viewsQ: Bar chart made in Python became "weird". Any suggestions how to improve it?
Friends, The following chart was generated: The code used was the following: # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import matplotlib.dates as dates from datetime import datetime,…
-
2
votes1
answer115
viewsQ: Graph of a Python denial of service attack
Friends, I generated the following chart: The code used was the following: import matplotlib.pyplot as plt import matplotlib.dates as dates from datetime import datetime, timedelta x = [] y = []…
-
1
votes1
answer3096
viewsQ: How to extract specific data from a Python text file?
I have a **text file of 49633 lines** (txt file) with the following format: -e Tue Mar 28 20:17:01 -03 2017 total used free shared buffers cached Mem: 239956 126484 113472 4904 10292 52280 -/+…
-
-1
votes1
answer1178
viewsQ: Reading an XML file and printing specific fields using the Python language
I have the following XML file (actually it’s just a piece of the file): <!DOCTYPE sysstat PUBLIC "DTD v2.19 sysstat //EN" "http://pagesperso-orange.fr/sebastien.godard/sysstat-2.19.dtd">…
-
1
votes1
answer171
viewsQ: Memory and CPU consumption during a denial of service attack. How to understand statistics?
The following line was on the Ubuntu crontab: */2 * * * * echo -e "`date`\n\n`free` \n\n`vmstat`\n" >> /home/hacker/free_vmstat_output.txt Extract from the free_vmstat_output.txt file two…
-
0
votes1
answer845
viewsQ: Automate reading multiple text files in a Python script
I have a Python script that counts the number of connections contained in a text file and that is working perfectly: with open('1zao.txt') as f: linhas = f.readlines() soma = 0 for linha in linhas:…
-
1
votes1
answer968
viewsQ: Python chart does not display all desired values
I would like only the values of the x, y coordinates corresponding to the points to appear in the graph. But it’s not like this: For example: The point whose x coordinate is 04/10/2017 09:41:00 does…
-
0
votes2
answers439
viewsQ: Python graph does not display values correctly
I’m trying to learn how to make graphics in Python. I made one now and it didn’t get very good: All dates are on April 10, 2017, coming only the time from 07h50:00 until 08h40:00 (GMT -3h) In the…
-
1
votes2
answers480
viewsQ: Deleting lines only if any cell in the worksheet is empty (using a script)
I have a spreadsheet from Calc (libreoffice)/Excel (actually it’s a text file that I opened as a spreadsheet for easy viewing) that contains some blank cells (not the entire line): I would like it…
-
1
votes2
answers159
viewsA: Extracting Window and Time values from a network dump
The simplest way is with tshark: tshark -r "1.pcap" -Tfields -e frame.time_epoch -e tcp.window_size_value >> arquivo.txt
-
1
votes2
answers159
viewsQ: Extracting Window and Time values from a network dump
The following network dump (PCAP format file) is the result of capturing a denial of service attack in the laboratory: I would like to extract the time (Unix time) and the window value (win) and…
-
1
votes1
answer50
viewsQ: Graph using local time instead of GMT time
import matplotlib.pyplot as plt import matplotlib.dates as dates from datetime import datetime, timedelta x = [] y = [] dataset = open("datasetDdos10Abril2017_unixtime.csv","r") ##separacao no csv…
-
3
votes1
answer358
viewsQ: Graph of total connections per second during a denial of service attack
I have a network dump (PCAP file) containing slowloris attacks: The following script will show the number of connections per second to IP 192.168.1.2 at port 80: tcpdump -qns 0 -A -r 1.pcap host…
-
2
votes1
answer116
viewsQ: Displaying total connections to a certain IP address
I have a network dump (PCAP file) containing attacks slowloris. The following script will show the number of connections to IP 192.168.1.2 on port 80: /usr/sbin/tcpdump -anr myfile.pcap | sed…
-
2
votes1
answer1506
viewsQ: Running external programs with Python
I would like to reduce the size of several Mp3 files in a directory with: ffmpeg -i k.mp3 -acodec libmp3lame -ac 2 -ab 16k -ar 44100 k_.mp3 where K is the name of the Mp3 (k from 1 to 8): I tried…