Search This Blog

Showing posts with label network. Show all posts
Showing posts with label network. Show all posts

Wednesday, February 05, 2025

RPI network reconnect

to be run */10 * * * * from cron

#!/bin/bash

wlan='wlan0'
gateway='192.168.1.1'

ping -c2 $gateway 2>&1 >/dev/null; rc=$?
if [[ $rc -eq 0 ]] ; then
        echo `date +"%b %d %T "`$0": The network is up."
else
        echo `date +"%b %d %T "`$0": Network down! Attempting reconnection."
        if [ -f /storage/.cache/nonet ]; then
                rm -f /storage/.cache/nonet
                reboot
        fi
        ifdown $wlan
        rmmod brcmfmac
        sleep 2
        modprobe brcmfmac brcmfmac_wcc
        ifup --force $wlan
        sleep 2
        connmanctl connect wifi_dc345a1743d_6e6545675289d3567_managed_psk &>/dev/null
        sleep 10
        ping -c2 $gateway 2>&1 >/dev/null; rc=$?
        if [[ $rc -ne 0 ]] ; then
                echo "1" > /storage/.cache/nonet
        fi
fi
exit 0

 

Monday, May 04, 2015

dns_adblock

#!/bin/bash 
#dns_adblock.sh - poor man's adblock 
# (c)2015 sorin@toXX.guru                                                                                       
#replace add servers with a local blank page 
#this script works faster/better/cleaner if you have apache httpd configured to serve a null page in case of page not found 
#just create an empty file 'touch /var/www/html/null.html', then in /etc/httpd/httpd.conf add/modify the line 'ErrorDocument 404 /null.html'  


#define local variables 
target=/var/named/data/blacklist

nullzone=/var/named/null.zone.file 
namedconf=/etc/named.conf  
whitelisted=/var/named/data/whitelisted.personal 
blacklisted=/var/named/data/blacklisted.personal 
namesrv=192.168.18.100                                                                           
# if it's the first time we run this, add the right info into bind's configuration   
if [ ! -f $nullzone ]; then  
echo "\$TTL    86400   ; one day  
@       IN      SOA     ads.nodomain. root. (  
             2015021505 ; serial              
                  28800 ; refresh                  
                   7200 ; retry                        
                 864000 ; expiry                        
                86400 ) ; minimum                          
            NS      nameserver     
               A       $namesrv              
@       IN      A       $namesrv                    
*       IN      A       $namesrv" > $nullzone    
fi                                                                                
if ! grep -q $target $namedconf ; then                                             
echo "conf not found"  

echo " include \"$target\";" >> $namedconf 
fi           
                                               

# get the list of known adservers from yoyo.org, sanitize it and make it compatible with bind9   
wget -q -O - 'http://pgl.yoyo.org/as/serverlist.php?hostformat=bindconfig&showintro=0' | tail -n+29 | head -n -6 | sed -e 's/{/IN {/g' -e '/_/d' > $target-new 

                                  
# get a second list from mvps.org, sanitize it and add only the hostnames that were not given by yoyo.org 
while read adhost; do                                                              
if ! grep -q $adhost $target-new ; then  
echo "zone \"$adhost\" IN { type master; notify no; file \"null.zone.file\"; };" >> $target-new   
fi          
done < <(wget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | sed -e '/^ *#/d;s/#.*//' -e '/^[[:space:]]*$/d' -e '/localhost/d' -e '/_/d' -e '/[\r\n]/d' | cut -d" " -f2 )          
             
# add personal blacklist    
blhost="nothing"  
sed '/^ *#/d;s/#.*//' $blacklisted | while read blhost; do  
if ! grep -q $blhost $target-new ; then                    
echo "zone \"$blhost\" IN { type master; notify no; file \"null.zone.file\"; };" >> $target-new  
fi        
done   

       
# remove whitelisted domains. ($wlisted variable have to be defined, otherwise sed might remove everything) 
wlisted="nothingatall"               
sed '/^ *#/d;s/#.*//' $whitelisted | while read wlisted; do 
sed -i /"$wlisted"'/d' $target-new                                                  done  

       
#remove duplicates, named is intolerant to multiple definitions for the same host  
cat  $target-new | sort -u > $target 


#cleanup line containing "empty" domain                                            
sed -i '/\"\"/d' $target 


# cleanup the last remanents of bad lines reported by named-checkconf  
if [ ! $(/usr/sbin/named-checkconf -t /var/lib/named -z /etc/named.conf >/dev/null 2>&1; echo $?) = 0 ]; then 
badlines=$(/usr/sbin/named-checkconf -t /var/lib/named -z /etc/named.conf | cut -d: -f2 | sed -e 's/$/d;/' | tr -d '\n')  
sed -i "$badlines" $target  
fi                                                                                    
rm -f $target-new                                                                                     
# reload bind  
/bin/systemctl reload named.service 




Sunday, August 10, 2014

Tune UP (in fact down) Windows 2008 R2

sssc config lanmanworkstation depend= bowser/mrxsmb10/nsi
sc config mrxsmb20 start= disabled

netsh int tcp set global rss=disabled
netsh int tcp set global chimney=disabled
netsh int tcp set global autotuninglevel=disabled
netsh int ip set global taskoffload=disablednetsh int tcp set global autotuninglevel=disablednetsh int tcp set global ecncapability=disablednetsh int tcp set global timestamps=disablednetsh advf set allp state off


:: reg add "HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters" /v DisableTaskOffload /t REG_DWORD /d "1" /f

reg add "HKLM\SYSTEM\CurrentControlSet\services\LanmanWorkstation\Parameters" /v DisableBandwidthThrottling /t REG_DWORD /d "1" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp" /v TcpAutotuning /t REG_DWORD /d "0" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" /v TcpAutotuning /t REG_DWORD /d "0" /f
reg add "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings" /v TcpAutotuning /t REG_DWORD /d "0" /f
reg add "HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters" /v EnableTCPA /t REG_DWORD /d "0" /f

Sunday, December 22, 2013

Logon Script

@echo off
color 0B
TITLE Initialization de connexion avec le serveur...
echo (c)2012 Xxxxxxxx Inc. Test de la connexion...  ^


REM ********** define per location variables *********
set server=myserver
set serverip=123.45.67.89
set group=mygroup
set domain=MYDOMAIN
set mypassword=pass_1234
set maping1=net use X: \\%server%\home\%username% /yes
set maping2=net use W: "\\%server%\Dossier Partages" /yes
set maping3=net time \\%server% /set /yes
set groupmaping=net use Z: \\%server%\specialshare /yes
set vpn=rasdial "VPN connection" %username% %mypassword%
REM ********** end of specific variables *************

REM *** define generic variables ***
set tmpvar=0
set hostspath=%windir%\System32\drivers\etc\hosts
set lmhostspath=%windir%\System32\drivers\etc\lmhosts

REM *** check if the servername is added to hosts file ***
type %hostspath% | find "%server%" 1>nul 2>nul
if errorlevel 1 goto NOTFOUND

REM *** check if the server is accessible. launch vpn first if you have to ***
:FOUND
%vpn%
ping -n 5 %server% | find "TTL" 1>nul 2>nul
IF %ERRORLEVEL% == 0 goto GOOD
IF NOT %ERRORLEVEL% == 0 goto BAD

REM *** if the server is accessible map the drives and launch a second script from server ***
:GOOD
%maping1% 1>nul 2>nul
%maping2% 1>nul 2>nul
%maping3% 1>nul 2>nul
@SET LANG=ENU
@SET FILE_SERVER=%server%
\\%server%\netlogon\oxlogon.bat

REM *** Special settings for members of certain Security Groups ***
for /f %%f in ('"net user /domain %username% | findstr /i %group%"') do set /a tmpvar=1
if %tmpvar% lss 1 goto END
%groupmaping%  1>nul 2>nul
goto END

REM *** if the server is not accessible let the user know ***
:BAD
ECHO Pas de connexion avec HQ. Verifiez le access Internet!
goto END

REM *** if the servername is not into hostfile add it ***
:NOTFOUND
echo. >> %hostspath%
echo %serverip% %server% >> %hostspath%
echo. >> %hostspath%
echo. >> %lmhostspath%
echo %serverip% %server% #PRE #DOM:%domain% >> %lmhostspath%
echo. >> %lmhostspath%
echo Ajout de %server% dans %hostspath%
goto FOUND

REM *** end of script. let the user see the messages for a few seconds, then exit ***
:END
echo C`est fait, Merci!
ping -n 4 -w 1000 1.1.1.1 >nul
exit

Thursday, December 05, 2013

Network Teaming

add the file bonding.conf to /etc/modprobe.d/
add the files ifcfg-* to /etc/sysconfig/network-scripts/ and modify them
accordingly (HWADDR, IP, GW etc)


bonding.conf
 alias bond0 bonding

ifcfg.bond0
DEVICE=bond0
IPADDR=192.168.1.178
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
BONDING_OPTS="miimon=80 mode=2"
GATEWAY="192.168.1.1"
DNS1="192.168.1.4"
DNS2="192.168.1.253"
DOMAIN="mydomain.local"


ifcfg.eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
HWADDR="9C:8E:99:00:00:00" #Use the REAL MAC of the card


ifcfg.eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
HWADDR="9C:8E:99:
00:00:01" #Use the REAL MAC of the card

ifcfg.eth2 
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
HWADDR="9C:8E:99:
00:00:02" #Use the REAL MAC of the card