Created
April 25, 2015 17:38
-
-
Save nvsofts/799858f14e060c5af989 to your computer and use it in GitHub Desktop.
透過プロキシを自分のPCに構成するためのスクリプト等
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# NATルールをクリア | |
iptables -t nat -F | |
# 80番ポート宛の通信をローカルの3128番ポートにリダイレクト | |
iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port 3128 | |
# 22番、443番、873番ポート宛の通信をローカルの3129番ポートにリダイレクト | |
iptables -t nat -A OUTPUT -p tcp --dport 22 -j REDIRECT --to-port 3129 | |
iptables -t nat -A OUTPUT -p tcp --dport 443 -j REDIRECT --to-port 3129 | |
iptables -t nat -A OUTPUT -p tcp --dport 873 -j REDIRECT --to-port 3129 | |
# SSL等用のプロキシサーバをスタート(3129番ポート) | |
tcpserver -u 65534 -g 65534 127.0.0.1 3129 /usr/local/bin/sslproxy 2> /dev/null & | |
# Squidをスタート(3128番ポート) | |
rc-service squid start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <arpa/inet.h> | |
#include <netdb.h> | |
#include <linux/types.h> | |
#include <linux/netfilter_ipv4.h> | |
#define STDIN_FD (0) | |
#define SIZE (256) | |
#define NCAT "/usr/bin/ncat" | |
#define PROXY "proxy-east.uec.ac.jp:8080" | |
int main(void) | |
{ | |
char origDest[SIZE]; | |
char portBuf[SIZE]; | |
struct sockaddr_in sin; | |
socklen_t sinlen = sizeof(sin); | |
if (getsockopt(STDIN_FD, SOL_IP, SO_ORIGINAL_DST, &sin, &sinlen) != 0) { | |
return 1; | |
} | |
if (inet_ntop(AF_INET, (void *)&(sin.sin_addr), origDest, SIZE) == NULL) { | |
return 1; | |
} | |
snprintf(portBuf, sizeof(portBuf), "%hu", ntohs(sin.sin_port)); | |
execl(NCAT, NCAT, origDest, portBuf, "--proxy", PROXY, NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment