Network test
Jump to navigation
Jump to search
local network
outgoing ip
- ipv4:
ip -4 --oneline route get 1 | grep -oP '(?<=src\s)\d+(\.\d+){3}'
- ipv6:
ip -6 --oneline route get 1:: | grep -oP '(?<=src\s)[\da-f:]+'
host ip of specific network
- ipv4:
LOCAL_NETWORK=10.0.0.0/24 ip -4 --oneline address show to ${LOCAL_NETWORK} | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
- ipv6:
LOCAL_NETWORK=fc00::/7 ip -6 --oneline address show sto ${LOCAL_NETWORK} | grep -oP '(?<=inet\s)[\da-f:]+'
dns
name server resolver from specific dns
nslookup campisano.org 8.8.4.4
open ports
netstat -tulpn # OR ss -tulpn
network traffic
e.g. inbound from specified interface and excluding specified ports:
tcpdump -n -i eth0 host 187.126.64.20 and not tcp port 22 and not tcp port 80
network access
ping campisano.org
routing
traceroute -M tcp -N 100 -m 100 campisano.org
specific port access
telnet campisano.org 80 # or nc -vv -w 3 -z campisano.org 80
perl homemade telnet version
- in some basic system like cloud minimal virtual machines, there are no network utilities like telnet, so there is a simple perl implementation (using vanilla Socket package):
#!/usr/bin/env perl # from https://www.oreilly.com/openbook/webclient/ch04.html use Socket; $|=1; # autoflush sub open_TCP { # get parameters my ($FS, $dest, $port) = @_; my $proto = getprotobyname('tcp'); socket($FS, PF_INET, SOCK_STREAM, $proto); my $sin = sockaddr_in($port,inet_aton($dest)); connect($FS,$sin) || return undef; my $old_fh = select($FS); $| = 1; # don't buffer output select($old_fh); 1; } # If no parameters were given, print out help text $num_args = $#ARGV + 1; if ($num_args != 3) { print "Usage: telnet.pl <host> <port> <text>\n"; print "Example: telnet.pl www.campisano.org 80 \$'GET /wiki/en/Main HTTP/1.0\\r\\nHost: www.campisano.org\\r\\n\\r\\n'\n"; exit(-1); } $host=$ARGV[0]; $port=$ARGV[1]; $text=$ARGV[2]; # contact the server print "connecting $host:port ...\n"; if (open_TCP(F, $host, $port) == undef) { print "Error connecting to server at $ARGV[0]\n"; exit(-2); } # send the GET method with / as a parameter print "sending $text ...\n"; print F "$text"; # print out the response print "printing response ... \n"; print $_ while (<F>); close(F);
java specific ipv6 network behaviour =
from https://docs.oracle.com/javase/8/docs/technotes/guides/io/example/Ping.java
- compile a simple ping app
curl -O https://docs.oracle.com/javase/8/docs/technotes/guides/io/example/Ping.java javac Ping
- from host with both ipv4 and ipv6 networks
java -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false Ping 80 HOSTNAME HOSTNAME/IPV4:80 : TIMEms java -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=true Ping 80 HOSTNAME HOSTNAME/IPV4:80 : TIMEms java -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true Ping 80 HOSTNAME HOSTNAME/IPV6:80 : TIMEms java -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=false Ping 80 HOSTNAME HOSTNAME/IPV4:80 : TIMEms java Ping 80 HOSTNAME HOSTNAME/IPV4:80 : TIMEms
- from host with only ipv6 network
java -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false Ping 80 HOSTNAME HOSTNAME/IPV4:80 : java.net.SocketException: Network is unreachable java -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=true Ping 80 HOSTNAME HOSTNAME/IPV4:80 : java.net.SocketException: Network is unreachable java -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true Ping 80 HOSTNAME HOSTNAME/IPV6:80 : TIMEms java -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=false Ping 80 HOSTNAME HOSTNAME/IPV4:80 : java.net.SocketException: Network is unreachable java Ping 80 HOSTNAME HOSTNAME/IPV4:80 : Timed out