Recent Notes
Displaying notes 161 - 170
Created by Dr. Xi on September 30, 2011 15:34:47
Last update: September 30, 2011 15:34:47
A naive try would be something like this:
$ nc -l 8082 | nc remote_host 80 Yes, it does forward the request from local port 8082 to remote_host:80 , but the response is dumped to stdout , not routed back to the client as expected. Using a named pipe makes it work: $ mkfifo backpipe $ nc -l 8082 0<backpipe | nc ... Use tee to get a glimpse of the response through the pipe (I wasn't able to find a way to dump the request): $ nc -k -l 8082 0<backpipe | nc localhost 80 | tee... The GNU netcat has a different syntax than the stock nc . It also supports different switches. To listen to port 1234: $ netcat -l -p 1234...
Created by woolf on September 30, 2011 13:58:02
Last update: September 30, 2011 13:58:14
Use IO redirection to swap stdout and stderr :
$ prog 3>&1 >&2 2>&3 3>&-
Created by woolf on July 19, 2011 09:06:49
Last update: September 30, 2011 11:52:19
Nmap port scan against host 10.2.1.3 , with TCP SYN scan ( -sS ), OS detection ( -O , capital O, not zero) and verbose output ( -v ):
nmap -v -sS -O 10.2.1.3
If ping is blocked, add switch -PN :
nmap -v -sS -O -PN 10.2.1.3
Shortcut option -A for version detection, Nmap Scripting Engine with the default set of scripts, remote OS detection, and traceroute (equivalent to: -sV -sC -O --traceroute ):
nmap -A 10.2.1.3
Created by voodoo on September 30, 2011 08:22:39
Last update: September 30, 2011 08:22:39
This iptables rule redirects all port 80 traffic from subnet 192.168.0.0/24 to 192.168.0.1 running HTTP proxy (say squid):
/usr/sbin/iptables -A PREROUTING -s 192.168.0.0/25...
Created by freyo on September 29, 2011 16:01:31
Last update: September 29, 2011 16:09:37
With standalone broadcast receiver
AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifes...
Java code:
package com.android.networkreceiver;
import...
Register listener inside Activity programmatically
AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifes...
Java code:
package com.android.networklistener;
import...
Register/unregister broadcast receiver in onResume / onPause works because the connectivity change broadcast is sticky . I intentionally used two registerReceiver calls in onResume to demonstrate this - onReceive will be called once for each registration.
Created by freyo on September 29, 2011 15:43:12
Last update: September 29, 2011 15:43:12
I got this error while enabling/disabling wifi on an Android device:
W/ActivityManager( 2735): Unable to launch app com...
The receiver was registered for network connection change:
<receiver android:name="NetworkReceiver">
...
This was fixed by just rebooting the device!
Created by magnum on September 24, 2011 13:14:37
Last update: September 28, 2011 18:08:35
There are two sides to an IP socket: the local side and the remote side:
The getpeername function retrieves the peer address of the specified socket.
#include <sys/socket.h>
int getpeername(int soc...
Example:
struct sockaddr_in addr;
socklen_t socklen = si...
The getsockname function retrieves the locally-bound name of the specified socket.
#include <sys/socket.h>
int getsockname(int soc...
Example:
struct sockaddr_in addr;
socklen_t socklen = si...
Created by magnum on September 27, 2011 21:51:05
Last update: September 28, 2011 18:02:49
Client socket usually does not call bind . But I've seen code that does and it was puzzling to me what bind does to a client socket. Therefore, this little test program. It retrieves a web url and displays info about the socket. You can optionally give a bind host name/ip and port and see what it does.
Here are my test results:
$ ./client www.google.com
Local addr: 172.16.0....
This is the code:
#include <stdio.h>
#include <stdlib.h>
#incl...
Created by magnum on September 28, 2011 09:31:58
Last update: September 28, 2011 09:31:58
This procedure works for xl2tpd . Edit L2TP configuration file /etc/xl2tpd/xl2tpd.conf :
; ; This is a minimal sample xl2tpd configurati... Edit PPP options file for L2TP /etc/ppp/options.xl2tpd.client : ipcp-accept-local ipcp-accept-remote refuse-... Edit PPP authentication file /etc/ppp/chap-secrets : # Secrets for authentication using CHAP # serve... Start xl2tpd : # /etc/init.d/xl2tpd start Connect to the server: # echo "c vpnserver" >/var/run/xl2tpd/l2tp-control Tail /var/log/messages , you should see something like: Sep 28 11:05:46 sta101894 pppd[26059]: pppd 2.4.5 ... ifconfig should show that ppp0 is added: # ifconfig ppp0 ppp0 Link encap:Point-to-P... To tear down the vpn: # echo "d vpnserver" >/var/run/xl2tpd/l2tp-control If authentication fails, try to set "require authentication" to no on both server and client and restart xl2tpd on both sides: # /etc/init.d/xl2tpd restart # echo "c vpnserve......
Created by magnum on September 23, 2011 16:06:02
Last update: September 28, 2011 09:29:53
This procedure works for xl2tpd .
Edit L2TP configuration file /etc/xl2tpd/xl2tpd.conf :
; Sample l2tpd.conf
;
[global]
; listen...
Edit PPP options file for L2TP /etc/ppp/options.xl2tpd :
ipcp-accept-local
ipcp-accept-remote
ms-dns ...
Edit PPP authentication file /etc/ppp/chap-secrets :
# Secrets for authentication using CHAP
# serve...
Start the server:
# /etc/init.d/xl2tpd start
Monitor the log:
# less /var/log/messages