Skip to main content

Posts

Showing posts with the label networking

Check multiple IPs via bash one-liner loop using ping or dig

Ping multiple Linux servers via Bash script. Pinging a Linux server sounds a very common and simple task for any SysAdmin. However, if there are quite a few IP Addresses to check, it's quite daunting as typing on the terminal window is quite tedious and prone to error or mistype. Bash script is a way to go for this type of task. Just prepare all the IP Addresses that needs to be checked in a single text file. Do a loop to check all the IP Addresses on the text file and just watch the Bash do its job. Here's a simple code to do it: for ipx in $(cat ipx.txt); do ping -c 3 $ipx; done ipx.txt <<< should contain all IP Addresses to be checked Example of ipx.txt contents: 1.2.3.4 4.5.6.7 10.10.10.1 .... .... etc.. Above command can also be used to check DNS Reverse record using dig. Example: for ipx in $(cat ipx.txt); do dig -x $ipx; done The above will perform a reverse DNS lookup. There's a lot of uses cases that can be done, with the above command. That's it. Enjo...

Linux SSH using Python and run remote commands

 SSH in Linux using Python and run commands on remote server A simple code snippet in Python to SSH to a remote system on a Linux Enviroment and run some commands Simple code snippet below, to get the serial number host on a remote system and save the output to the local host where the Python was executed. Python code snippet below is just a two-liner, that will SSH to a remote system and execute some commands and save the output locally. Save the output as "ssh_get_serial.py" or any filename as desired, and run as python3 ssh_get_serial.py. import subprocess  subprocess.Popen("ssh {user}@{host} {cmd}".format(user='root', host='server.web01.internal', cmd='s dmidecode -t system | egrep "Serial|Product";hostname > /tmp/server-sn-check.txt '), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() import subprocess <-- module to be imported in Python subprocess.Popen("ssh {user}@{host} {cmd}" {user} ...

Ping device using Python

Below is a simple Python code that accepts IP Address as input and check or ping the IP Address and shows an output whether its up or down. Some network disable ICMP request, so no matter how you try the system will not reply to the ping request. Code below is great when you're getting hands wet on simple Python script. Here's the code: #!/usr/bin/python3  import subprocess as subps  import sys  def ipcheck(check_ice):    status,result = subps.getstatusoutput("ping -c1 -w2 " + str(check_ice))    if status == 0:       print("Device " + str(check_ice) + " is UP!")       print(status,result)   else:       print("Device " + str(check_ice) + " is DOWN!") ipcheck(str(sys.argv[1]))  #================ Works great on Linux system. For Windows, run on WSL environment. Type: wsl to enable WSL Then change directory to: /mnt/c/Users/<username>/Documents  Or cd /mnt/c/<browse to wh...

Unable to browse website or the internet

In today's digital world, browsing website is a must. And if unable to browse then it could be an issue especially if you need to get things done. You need a piece of code but unable to browse StackOverflow is quite terrifying for a person developing a simple program. Others don't care how things work, they just want to get things done and that's it. But if unable to browse a website there could be a lot of things involved. Here are some possible issues why unable to browse a site or the Internet. Of course the list below is just a small fraction of why unable to browse the Internet.   - Website or URL trying to browse is not available or server that host the website is down or offline - Website or URL is typed incorrectly on the address bar - Website is a non www URLs, example website is only http:\\thewebsite.com other than www.thewebsite.com - Website TLD or Top-Level Domain is incorrectly entered the site ends .net or .org .mil or other TLDs - Some website...

PowerShell Ping IPV4 addresses

Ping a range of IPV4 and resolve its hostnames via PowerShell. Here’s a simple PowerShell code snippet to ping a range of an IPV4 addresses and any IP address that will reply will be shown as per the sample output below. #======================   ( 240 .. 254 | ForEach {     write $_     Test-Connection -computername "192.168.8. $_ "   -count 1 -erroraction 'silentlycontinue' | Format-Table -AutoSize   })   #====================== 240 .. 254 –- change this to a desired IP range from 1 to 254. 192.168.8. $_ -- change this IP Address on the IP Address configured or set on the network -count 1 –- ping 1 time -erroraction 'silentlycontinue' –- this will not display any errors on the screen if the IP Address can’t be found or is not set to reply to ICMP or ping protocol Format-Table -AutoSize –- if the device will reply with the hostname then the full name will be displayed on the screen and not trunca...

Windows release DHCP IP Address and get a new one

 Working remotely is quite a norm in today's pandemic world.  IT / System Admin working remotely may find it difficult or a good opportunity to work at the comfort at their own homes. Difficult in a way, when something goes wrong on a server or any device and you need a physical hand even just to force power off and turn it back on may seem an impossible task. DHCP is an amazing technology that lets machines auto configured themselves with an IP Address without human intervention. But not everything seems to work smoothly at times, and if you have multiple networks in a single manage switch. Changing one network from another makes life easier using a manage switch. However, the machine, server or computer may not change easily; you either need to reboot the machine or just simply release and renew the DHCP to set or get the desired IP Address from a new network profile. In Windows DHCP network, ipconfig /release will release the IP and the machine will be automat...

PPTP VPN not connecting

Ever encounter connecting PPTP VPN from a Ruckus router or other new routers but VPN keep on failing? Or does not connect at all. However, if you test the VPN outside the network of the Ruckus router or use another Wi-Fi Router the VPN goes through and able to connect. One reason is the Wi-Fi router does not allow the unsecure PPTP VPN protocol to pass through. The firmware filters the PPTP traffic. PPTP VPN has quite a few vulnerabilities and some Wi-Fi router does not allow this protocol to pass through for some obvious reason, because it could compromise the network security. Solution is to select another VPN protocol that is supported by the Wi-Fi router and is considered a secure protocol.  To easily troubleshoot whether it’s the Wi-Fi router that is filtering the VPN protocol, is to grab some old Wi-Fi router if ever you have some that is just lying around and collecting dust. And check whether VPN goes through. If it goes through, then the firm...

PowerShell Ping IP get status or reply

How to ping sweep a network? How to ping sweep a subnet? There’s a lot of ways to ping the whole subnet or do a sweep ping to the whole network, of course download any free software that can do this, or just manually ping the whole network by manually changing the IP address. Or do an old school method, using a batch file. This link shows how to ping the whole subnet via command line. http://quickbytesstuff.blogspot.sg/2015/11/how-to-ping-whole-subnet-using-batch.html Since PowerShell is readily available from Windows 7 up to the newer versions of Windows. Then PowerShell is the perfect choice to do this task. Open PowerShell ISE or the PowerShell command line, then type or copy the commands below: $ping = New-Object System.Net.Networkinformation.Ping 1..254 | % { $ping.send(“192.168.1.$_”) | select address, status | ft -auto } Change the IP Address (192.168.X.X) to the IP address range of your network. What the script does, is to Ping the whole ...

PowerShell Test Port Forwarding - check if port is open

Port forwarding is necessary if the device is that needs to connect to the unsecured world of the Internet. Of course, before opening port or doing any port forwarding make sure that security is in place. Firewall rules, software configuration are properly set, up-to-date anti-virus and other settings that needs to be done to secure the system. PowerShell can test whether a remote port is open or a Port Forwarding rules on either on the Firewall or router is set correctly. Here’s a one liner code, to check whether the Port is open or not. Both one line code below does the same thing, check whether the Port is open or not. 1 . New-Object System.Net.Sockets.TCPClient -ArgumentList "Remote.Public.IP.Address", 3389 2. Test-NetConnection -Port 80 -InformationLevel Detailed Replace the port number, with any port number to be tested. If the connected property on the displayed output is true, then the port is open. More details on the link b...