Outils pour utilisateurs

Outils du site


blog

Note curl wget

URL / URI

Voir :

URI (Uniform Resource Identifier) :

  • Name : URN (Uniform Resource Name)
  • Location : URL (Uniform Resource Locator)
URI

URL, URI and URN

URL

En anglais, on la décrit ainsi :

scheme : // authority / path ? query # hash 

Dans sa traduction française :

plan : // autorité / chemin ? requête # fragment 

Enfin , comme on l'explique à notre manière :

comment : // chez_qui / où ? question # extrait 

Source : https://cpu.dascritch.net/post/2023/10/12/Standard-%3A-%28Rappel%29-les-segments-d-une-URL

Syntax of URL

scheme: subdomain/domain-name.Top-level-domain/sub-folder

wget / curl

curl as wget

curl -O -L http://acme.org/download/plop.tar.gz

Point wget to TOR/Privoxy:

#export http_proxy=http://127.0.0.1:8118/
#export https_proxy=http://127.0.0.1:8118/
export ALL_PROXY=http://127.0.0.1:8118/
 
# Ou
 
curl -x "http://127.0.0.1:8118" "http://gnu.org"

curl

Voir aussi HTTPie

Voir Utiliser les REST API JSON avec cURL

JSON

curl -k https://aap-controller.local/api/v2/users/27/roles/ -X POST -u user:password --data-raw '{"id":534}'

Préciser le host sans modifier les /etc/hosts

curl -H "Host:www.acme.fr" 192.168.2.14:80 

Meteo (Basé sur Wego)

curl -4 wttr.in
curl -H "Accept-Language: it" wttr.in/Rome

/etc/hosts

curl --resolve www.acme.fr:80:192.168.2.10 \
     --resolve www.acme.fr:443:192.168.2.10 \
     http://www.acme.fr

Forcer SSLv3 Pour vérifier que ça ne marche pas, car ca chiffrement est obsolète -k Pour les certificat auto-signé

Voir CURLOPT_SSLVERSION

curl -3 -k --show-error --verbose https://acme.fr

Erreur status code

curl --show-error --verbose -I http://www.acme.fr
curl --write-out "\nhttp_code=%{http_code}\ total_time=%{time_total}\n"

Add GPG key

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

-f : Fail silently on server errors
-s : Silent or quiet mode. Don't show progress meter or error messages
-S : When used with -s, --silent, it makes curl show an error message if it fails
-L : If the server reports that the requested page has moved to a different location, this option will make curl redo the request on the new place.

Fichier config .curlrc

.curlrc

# Source : https://gist.github.com/v1m/f1d4751883f19c916515

# store the trace in curl_trace.txt file. beware that multiple executions of the curl command will overwrite this file
--trace curl_trace.txt

# store the header info in curl_headers.txt file. beware that multiple executions of the curl command will overwrite this file
--dump-header curl_headers.txt

#change the below referrer URL or comment it out entirely
-e "https://www.google.com"

#change the below useragent string. get your/other UA strings from http://www.useragentstring.com/
-A "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13"

#some headers
-H  "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
-H  "Upgrade-Insecure-Requests: 1"
-H  "Accept-Encoding: gzip, deflate, sdch"
-H  "Accept-Language: en-US,en;q=0.8"

.curlrc

Source https://github.com/necolas/dotfiles/blob/0d402c916f6e1118b20bd4befff863c1e4a2ee2d/shell/curlrc

# Limit the time (in seconds) the connection to the server is allowed to take
connect-timeout = 30

# Limit the time (in seconds) the whole operation is allowed to take
# (prevents cURL from hanging due to slow networks or links going down)
max-time = 300

# When following a redirect, automatically set the previous URL as referer
referer = ";auto"

# cURL default configuration file
# http://curl.haxx.se/docs/manpage.html

# Show error messages
show-error

# Show progress using a progress meter
progress-bar

# Send a fake UA string for the HTTP servers that sniff it
user-agent = "Mozilla/5.0 Gecko"

Upload

HTTP POST files here:
    curl --proxy 127.0.0.1:4444 -F'file=@yourfile.png' http://0xff.i2p

Or with status bar:
    curl --proxy 127.0.0.1:4444 -T yourfile.png http://0xff.i2p | tee

Upload command output:
    command | curl -T - --proxy 127.0.0.1:4444 http://0xff.i2p

Upload command output with stderr:
    command 2>&1 | curl -T - --proxy 127.0.0.1:4444 http://0xff.i2p

Or you can shorten URLs:
    curl --proxy 127.0.0.1:4444 -F'shorten=http://example.com/some/long/url' http://0xff.i2p

wget

Autres

wget --no-cache --no-cookie
wget - preserve filename
wget https://getsession.org/linux
# Saving to: 'linux'
 
wget --content-disposition https://getsession.org/linux
# Saving to: 'session-desktop-linux-x86_64-1.8.6.AppImage'
 
wget -O plop https://getsession.org/linux
# Saving to: ‘plop'
Autres

Fix curl client certificate error: curl: (58) unable to set private key file http://honglus.blogspot.fr/2012/03/fix-curl-client-certificate-error-curl.html

15 Practical Linux cURL Command Examples (cURL Download Examples) http://www.thegeekstuff.com/2012/04/curl-examples/

Download the webpage with wget. The wget options (-E, -k, etc.) are CASE SENSITIVE! The maximum depth to which the retrieval may descend is specified with the ‘-l’ option:

wget -E -k -p -nd -r -l 1 -np -P <local-folder-name> http://site-to-be-mirrored.org

wget : Ignore robots restrictions

wget -e robots=off --wait 1 http://your.site.here

Dossier répertoire directory

wget http://www.claudiokuenzler.com/nagios-plugins/check_equallogic.sh -P /usr/lib/nagios/plugins/ 

A partir d'un fichier d'URL

wget --no-proxy -i providers.txt -P /usr/share/terraform/providers/registry.terraform.io/hashicorp/vsphere
Notes exemple Dokuwiki

wget

wget --max-redirect=4 --output-document=siteexport.zip --post-data="id=dokuwiki&depth=0&depthType=0.0&do=siteexport&ens=dokuwiki&template=dokuwiki" https://acme.com/doku.php?id=doku.php --http-user=USER --http-passwd=PASSWD
wget -E -r http://wiki.foo.tld/doku.php?id=start -l 0 --header="X-DokuWiki-Do: export_xhtml"

curl

curl -L --max-redirs 46 -o siteexport.zip -d "id=dokuwiki&depth=0&depthType=1.0&do=siteexport&ens=dokuwiki&exportbody=1&renderer=&template=dokuwiki" https://acme.com/doku.php?id=doku.php --anyauth --user USER:PASSWD
Notes Curl certificat auto-signé

Pour ignoré le certificat

curl  -k https://www.acme.fr
wget --no-check-certificate https://www.acme.fr

Pour enregistrer le certificat et vérifier

openssl s_client -showcerts -connect www.acme.fr:443 -servername www.acme.fr </dev/null > cacert.pem
# ou
curl -k -w %{certs} https://www.acme.fr > cacert.pem

Tester

curl --cacert cacert.pem  https://www.acme.fr

ou avec wget

wget --ca-certificate=cert.pem https://www.acme.fr

Voir Installation de la CA sous GNU/Linux

Enlever la CA

rm /usr/local/share/ca-certificates/acme.fr.crt
update-ca-certificates --fresh

TODO : equivalement pour Redhat avec update-ca-trust

.curlrc

cacert=/home/jean/cert.pem

Ou, à éviter mais possible .curlrc

insecure

https sous java Voir la paquet ca-certificates-java

openssl s_client -showcerts -connect 192.168.4.13:5000 </dev/null > cert.crt
 
# test
curl --show-error --verbose --cacert cert.crt https://172.18.51.220:5000
 
cp cert.crt /usr/local/share/ca-certificates/acme.fr.crt
update-ca-certificates
 
/var/lib/dpkg/info/ca-certificates-java.postinst configure
systemctl restart jenkins

Python

import requests
 
# No warn for bad https 'verify=False'
requests.packages.urllib3.disable_warnings()
 
# HTTP GET all users ids
r = requests.get('https://aap.admin.acme.local/api/v2/users/', auth=(aap_user, aap_pass), verify=False)

Exemple HTTPS certificat client

curl --verbose --show-error --tlsv1.2 --cert /etc/httpd/ssl/acme.fr.crt --key /etc/httpd/ssl/acme.fr.key https://acme.net/plop
wget --debug --verbose --no-check-certificate --secure-protocol=TLSv1_2 --certificate=/etc/httpd/ssl/acme.fr.crt --private-key=/etc/httpd/ssl/acme.fr.key https://acme.net/plop
(echo -ne "GET /plop HTTP/1.1\r\nHost: acme.net\r\n\r\n" ; cat ) |openssl s_client -connect acme.net:443 -servername acme.net -cert /etc/httpd/ssl/acme.fr.crt -key /etc/httpd/ssl/acme.fr.key
curl --cacert keys/ca.crt --key keys/client1.key --cert keys/client1.crt https://pkiweb.lan
wget --ca-certificate=keys/ca.crt --private-key=keys/client1.key --certificate=keys/client1.crt https://pkiweb.lan

Envoyer un fichier en ligne de commande (upload web)

Goploader

# Your file will be named myfile.txt
curl -F file=@myfile.txt https://up.depado.eu/
 
# Your file will be named myamazingfile!
curl -F name="myamazingfile!" -F file=@myfile.txt https://up.depado.eu/
 
# Reads data from stdin
cat myfile.txt | curl -F name="stdin" -F file=@_ https://up.depado.eu/

Sécurité

Pipe bash

https://www.idontplaydarts.com/2016/04/detecting-curl-pipe-bash-server-side/

curl -sSk http://pluver.xqi.cc/setup.bash
curl -sSk http://pluver.xqi.cc/setup.bash |bash 
2025/03/24 15:06

Note CSS

Les tableaux

<style type="text/css">
table tr:nth-child(odd) td
{
        background-color: #E0E0F7;
}
 
tr td:first-child
{
        text-align: right;
}
</style>
2025/03/24 15:06

Notes cross-compilation

Voir : https://blog.svgames.pl/article/cross-compiling-c-programs-for-ms-windows-using-mingw

apt-get install crossbuild-essential-i386

Ou

cat /etc/apt/sources.list |grep debian |sed -e 's/stretch/jessie/g' |grep -v deb-src > /etc/apt/sources.list.d/jessie.list
 
dpkg --add-architecture i386
apt-get update
 
apt-get install mingw32 mingw32-binutils
#apt-get install mingw-w64

plop.cpp

#include <iostream>
 
int main(int argc, char** argv)
{
    std::cout << "Hello" << std::endl;
    return 0;
}
i586-mingw32msvc-g++ -o plop.exe plop.cpp

On windows error libstdc++-6.dll missing

Pour le plus avoir l'erreur
Nous ne voulons plus de DLL, donc mettons tout en static

i586-mingw32msvc-g++ -o plop.exe plop.cpp
aptitude search '~n curl ~r i386'
 
apt-get source curl:i386
apt-get source libcurl3:i386 libcurl3-gnutls:i386
cd curl
 
#apt-get install crossbuild-essential-i386
 
export ARCH=i386 CROSS_COMPILE=arm-linux
make -f lazy_makefile CC=i686-w64-mingw32-gcc
./configure --host=i686-w64-mingw32 --enable-shared --disable-install-doc
./configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 
./configure --host=x86_64-w64-mingw32 --disable-magic --disable-cuckoo --with-crypto CFLAGS=-I/root/openssl/include LDFLAGS=-L/root/openssl/lib --enable-static
 
The right way to do this is to add the ''-static'' flag to an ''LDFLAGS'' variable. For all targets: ''AM_LDFLAGS=-static''
 
export CC=i586-mingw32msvc-cc
./configure --host=i686-w64-mingw32 --enable-static
 
export CFLAGS='-static'
 
make V=1 curl_LDFLAGS=-all-static
 
 
git clone -b curl-tiny-7.72 https://github.com/curl/curl.git
libtool:   error: Could not determine the host path corresponding to
libtool:   error:   '/home/jibe/code/i386/curl-7.52.1/lib/.libs'
libtool:   error: Continuing, but uninstalled executables may not work.
libtool:   error: Could not determine the host path corresponding to
libtool:   error:   '/home/jibe/code/i386/curl-7.52.1/lib/.libs:/usr/local/lib:/usr/local/bin'
libtool:   error: Continuing, but uninstalled executables may not work.
make[2]: Leaving directory '/home/jibe/code/i386/curl-7.52.1/src'
make[1]: Leaving directory '/home/jibe/code/i386/curl-7.52.1/src'
Making all in include
make[1]: Entering directory '/home/jibe/code/i386/curl-7.52.1/include'
Making all in curl
make[2]: Entering directory '/home/jibe/code/i386/curl-7.52.1/include/curl'
make  all-am
make[3]: Entering directory '/home/jibe/code/i386/curl-7.52.1/include/curl'
make[3]: Leaving directory '/home/jibe/code/i386/curl-7.52.1/include/curl'
make[2]: Leaving directory '/home/jibe/code/i386/curl-7.52.1/include/curl'
make[2]: Entering directory '/home/jibe/code/i386/curl-7.52.1/include'
make[2]: Nothing to be done for 'all-am'.
make[2]: Leaving directory '/home/jibe/code/i386/curl-7.52.1/include'
make[1]: Leaving directory '/home/jibe/code/i386/curl-7.52.1/include'
make[1]: Entering directory '/home/jibe/code/i386/curl-7.52.1'
make[1]: Nothing to be done for 'all-am'.
make[1]: Leaving directory '/home/jibe/code/i386/curl-7.52.1'
$ find . -iname curl.exe
./curl-7.52.1/src/.libs/curl.exe
./curl-7.52.1/src/curl.exe

Le bon est celui qui est dans src/.libs/

export AM_LDFLAGS='-static'
 
git clone https://github.com/curl/curl.git
cd curl
git tag
git checkout curl-7_9_8
 
export ROOTDIR="${PWD}"
cd curl
#$ export CROSS_COMPILE="arm-none-linux-gnueabi"
#export CROSS_COMPILE="stable-i686-pc-windows-gnu"
export CROSS_COMPILE="i686-w64-mingw32"
#export CPPFLAGS="-I${ROOTDIR}/openssl/include -I${ROOTDIR}/zlib/include"
export CPPFLAGS="-I${ROOTDIR}/openssl/include/openssl -I${ROOTDIR}/openssl/include/crypto -I${ROOTDIR}/openssl/include/internal"
export LDFLAGS="-L${ROOTDIR}/openssl/libs -L${ROOTDIR}/zlib/libs"
export AR=${CROSS_COMPILE}-ar
export AS=${CROSS_COMPILE}-as
export LD=${CROSS_COMPILE}-ld
export RANLIB=${CROSS_COMPILE}-ranlib
export CC=${CROSS_COMPILE}-gcc
export NM=${CROSS_COMPILE}-nm
export LIBS="-lssl -lcrypto"
./buildconf
./configure --prefix=${ROOTDIR}/build --target=${CROSS_COMPILE} --host=${CROSS_COMPILE} --build=i586-pc-linux-gnu --with-ssl --with-zlib
sudo apt-get build-dep curl

Pb

Err

m32test.c

#include <stdio.h>
int main()
{
   printf("This works\n");
   return 0;
}
$ gcc -m32 -o m32test m32test.c
In file included from /usr/include/stdio.h:27:0,
                 from m32test.c:2:
/usr/include/features.h:364:25: fatal error: sys/cdefs.h: No such file or directory
 #  include <sys/cdefs.h>
                         ^
compilation terminated.
# gcc -m32 -o m32test m32test.c                                                                                                                                              
In file included from m32test.c:1:                                                                                                                                                            
/usr/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: No such file or directory
 #include <bits/libc-header-start.h>                                                                                                                                              
          ^~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                         
compilation terminated.

Solution

apt-get install gcc-multilib
Err undefined reference to
2025/03/24 15:06

Notes crontab

Voir aussi :

/etc/cron.d/plop
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
#
CRON_TZ=Europe/Paris

30 2 * * * root find /opt/plop/ -type f -name '*.old' -type f -mtime +20 -delete

Ici nous avons root en 6em position. Ce champs n'est présent uniquement pour les fichiers crontab dans /etc/cron.d

    (1) valeur comprise entre 0 et 59
    (2) valeur comprise entre 0 et 23
    (3) valeur comprise entre 1 et 31
    (4) valeur comprise entre 1 et 12
    (5) valeur comprise entre 0 et 7 (Dimanche étant le 0 ou le 7) ou alors les abréviations correspondant aux jours de la semaine en Anglais: sun,mon,tue,wed,thur,fri,sat
    (6) uniquement pour les fichiers crontab du système dans /etc/cron.d
    (7) commande à effectuer

Sur RedHat 7 / CentOS 7
il suffit d'ajouter le fichier dans /etc/cron.d/ rien à faire (pas de redémarrage)

at

2025/03/24 15:06
blog.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki