Skip to content

Instantly share code, notes, and snippets.

View SebDeclercq's full-sized avatar

Sébastien Declercq SebDeclercq

View GitHub Profile
#!/usr/bin/env perl
# Script qui scanne les ports d'un serveur afin d'y trouver
# les ports ouverts.
use warnings;
use strict;
use feature 'say';
use IO::Socket;
use Term::ANSIColor;
$|=1; # Autoflush

Perl - Socket Programming

https://www.tutorialspoint.com/perl/perl_socket_programming.htm

Introduction

Un socket permet d'établir une connexion virtuelle entre deux processus. Pour commencer, considérons qu'un socket a une adresse IP et un port et qu'il sert à établir la gestion des envois/réceptions de données.

Pour créer un serveur, il faut

  1. Créer un socket avec socket()
  2. Lier ce socket à un port avec bind()
  3. Écouter le port avec listen()
  4. Accepter les connexions de clients avec accept()
<html>
<body>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script>
function Personne(prenom, nom) {
this.nom = nom
this.prenom = prenom
this.say = function(verbe='Hello') {
alert(verbe+' '+this.prenom+' '+this.nom.toUpperCase())
}
<?php
// LES CLASSES
class Bibliotheque
{
protected $livres = array();
public function getLivres() {
return $this->livres;
}
public function ajouteLivre(Livre $livre) {
$this->livres[] = $livre;
<?php
class Json implements RessourceRestPersonne
{
static public function getPersonnes() {
$pdo = new PDO('mysql:host=localhost;dbname=test;charset=UTF-8', 'root', '');
$pdostmt = $pdo->prepare('SELECT * FROM rest;');
$pdostmt->execute();
$personnes = $pdostmt->fetchAll(PDO::FETCH_OBJ);
$pdo = null;
<?php
abstract class ModifiableAtRuntime
{
protected $methodes;
public function ajouteMethode($nom, Closure $closure) {
$this->methodes[$nom] = $closure->bindTo($this, __CLASS__);
}
public function __call($methode, $args) {
#/usr/bin/bash
function versUtf8() {
entree=$1;
sortie=${2:-versUtf8Output.txt};
charset=$(file -i $entree |grep -oP '(?<=charset=).*');
if [ $charset == 'unknown-8bit' ]
then
charset='windows-1252'
fi
<?php
class T
{
protected $methods = array();
public function addMethod($name, $closure) {
$this->methods[$name] = $closure->bindTo($this, __CLASS__);
}
@SebDeclercq
SebDeclercq / site_web.rb
Created April 17, 2016 20:31
Gère la bdd hiragana
require "sinatra"
require "sqlite3"
require "json"
db = SQLite3::Database.new "hiragana.db"
set :public_folder, "."
######################################################################################
### UI web
@SebDeclercq
SebDeclercq / comparison.org
Created February 23, 2015 09:38
Benchmark (comparison) between Perl and Ruby based on "Learning Perl" (complete) and on "Intermediate Perl" (up to chapter 4)

Learning Perl

  1. Chapter 2
    • exercise 3
      • Perl : 164 char
      • Ruby : 125 char
    • exercise 4
      • Perl : 168 char
      • Ruby : 166 char
    • exercise 5
      • Perl : 93 char