Categorieën
Linux

netplan config example

network:
ethernets:
eth0:
dhcp4: no
addresses: [103.167.143.203/29]
routes:
– to: 0.0.0.0/0
via: 103.167.143.201
nameservers:
addresses: [192.168.1.1]
optional: true
version: 2
wifis:
wlan0:
optional: true
access-points:

“XXX”:
password: “XXXXX”
dhcp4: no
addresses: [192.168.1.38/24]

Categorieën
Linux

Wireguard configuration example

Server

[Interface]
Address = 10.0.0.1/32
ListenPort = 123
PrivateKey = XXXX

[Peer]
PublicKey = XXX
AllowedIPs = 10.0.0.2/32

Client

[Interface]

Address = 10.0.0.2/32
PrivateKey = XXX

[Peer]

PublicKey = XXXXX
Endpoint = 103.167.143.203:123
AllowedIPs = 10.0.0.1/32
PersistentKeepalive = 21

Commands

wg-quick up wg0

Categorieën
MacSpoof

Ubuntu add mac spoof at boot

make file /etc/udev/rules.d/75-mac-spoof.rules

Store text:

ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="dc:a6:32:a1:23:e4", RUN+="/usr/bin/ip link set dev %k address dc:a6:32:a1:23:e9"

Reboot

Categorieën
Linux

Pyinstaller – fixing dropbox.rest.RESTSocketError – Dropbox python API SSL issue

When playing around with the python dropbox API to upload files, I ran into issues when trying to make a single executable using pyinstaller.

The error I received was similar as shown below:

pyinstaller-dropbox

I figured it had to do with the trusted-certs  file used by the dropbox API to validate its SSL connection to the dropbox servers.

To overcome this issue, I had to perform the below steps:

  1. First browse to your dropbox API folder and copy the trusted-certs.crt to another location

    In my case this was C:\Python27\Lib\site\packages\dropbox\

Copy trusted-certs.crt to d:\

   2. Stay in the dropbox api folder and open the rest.py file using your favorite editor program.

 3. Within rest.py file look for the section that starts with:

TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, ‘trusted-certs.crt’)

change this to:

def resource_path(relative_path):

“”” Get absolute path to resource, works for dev and for PyInstaller “””

try:

# PyInstaller creates a temp folder and stores path in _MEIPASS

base_path = sys._MEIPASS

except Exception:

base_path = os.path.abspath(“.”)

return os.path.join(base_path, relative_path)

TRUSTED_CERT_FILE = (resource_path(‘certs\\trusted-certs.crt’))

This will ensure that the dropbox API will look in the %temp% directory which the standalone .exe creates at runtime.

  4. Now you have to recompile rest.pyc so the dropbox API and pyinstaller use the changes made

Open python in CMD and run the following command (change the file path to fit your setup)

>>> import py_compile

>py_compile.compile(‘C:/Python27/Lib/site-packages/dropbox/rest.py’)

5. The final step is to create a pyinstaller .spec file in which you tell pyinstaller to copy and include the                        trusted-certs.crt file in the %temp% directory where it also writes files needed by the program at run time.

Do the following:

Run pyinstaller using the “yourprogram.py” file which you like to convert into a single exe file

In my case this is:

D:\pyinstaller find-copy.py

This will create a find-copy.spec file within the running directory (d:\). Copy and rename this file to something else like           myprog.spec.

Open myprog.spec and modify the following. Make sure the trusted-cert.crt path reflects your situation!

a = Analysis([‘find-copy.py’],

pathex=[‘D:\\’],

binaries=None,

             datas=[(‘d:/trusted-certs.crt’, ‘certs’)],

hiddenimports=[],

hookspath=None,

runtime_hooks=None,

excludes=None,

win_no_prefer_redirects=None,

win_private_assemblies=None,

cipher=block_cipher)

  6. You are no ready to re-run pyinstaller but this time specifying the myprog.spec file

In my case this looks like this:

Pyinstaller –F myprog.spec find-copy.py

  7. If all went well you should now have a working .exe file which copies and finds the required trusted-certs.crt         file needed by the dropbox API

Enjoy 😉

Categorieën
DNS Linux

How to resolve DNS queries using different DNS servers & without DNS forwarding

If you ever run in the issue were you have two different DNS servers that are both responsible to resolve different records and you are not allowed to configure DNS forwarding. You can use the following procedure on your Linux, Unix based distro:

 

  1. cd /usr/bin
  2. cp nslookup nslookup.orig
  3. rm nslookup
  4. vi nslookup
#!/bin/bashHOSTNAME=${1}

if [[ $HOSTNAME = 192.168.2* ]]; then

/usr/bin/nslookup.orig $HOSTNAME 192.168.2.110

elif [[ $HOSTNAME = *rsa.lab ]]; then

/usr/bin/nslookup.orig $HOSTNAME 192.168.2.110

else

/usr/bin/nslookup.orig $HOSTNAME 8.8.8.8

fi

  1. chmod 777 nslookup

As a result, internal IP addresses staring with 192.168.2.* and hostnames containing *.rsa.lab where resolved by the DNS server with IP 192.168.2.110 whilst everything else got resolved by the DNS server with IP 8.8.8.8.