specify port iptables linux only

This commit is contained in:
sirjonasxx 2020-06-11 21:36:13 +02:00
parent 62a5f696dd
commit 7470fb4533
6 changed files with 16 additions and 14 deletions

View File

@ -190,11 +190,11 @@ public class LinuxRawIpProxyProvider extends ProxyProvider {
protected void maybeAddMapping() { protected void maybeAddMapping() {
ipMapper.enable(); ipMapper.enable();
ipMapper.addMapping(proxy.getActual_domain()); ipMapper.addMapping(proxy.getActual_domain(), proxy.getActual_port(), proxy.getIntercept_port());
} }
protected void maybeRemoveMapping() { protected void maybeRemoveMapping() {
ipMapper.deleteMapping(proxy.getActual_domain()); ipMapper.deleteMapping(proxy.getActual_domain(), proxy.getActual_port(), proxy.getIntercept_port());
} }

View File

@ -48,7 +48,7 @@ public class WindowsRawIpProxyProvider extends LinuxRawIpProxyProvider {
hasMapped = true; hasMapped = true;
if (isNoneConnected()) { if (isNoneConnected()) {
ipMapper.enable(); ipMapper.enable();
ipMapper.addMapping(proxy.getActual_domain()); ipMapper.addMapping(proxy.getActual_domain(), proxy.getActual_port(), proxy.getIntercept_port());
} }
addMappingCache(); addMappingCache();
} }
@ -60,7 +60,7 @@ public class WindowsRawIpProxyProvider extends LinuxRawIpProxyProvider {
hasMapped = false; hasMapped = false;
removeMappingCache(); removeMappingCache();
if (isNoneConnected()) { if (isNoneConnected()) {
ipMapper.deleteMapping(proxy.getActual_domain()); ipMapper.deleteMapping(proxy.getActual_domain(), proxy.getActual_port(), proxy.getIntercept_port());
} }
} }
} }

View File

@ -18,9 +18,9 @@ public abstract class IpMapper {
abstract public void enable(); abstract public void enable();
abstract public void addMapping(String ip); abstract public void addMapping(String ip, int listenport, int connectport);
abstract public void deleteMapping(String ip); abstract public void deleteMapping(String ip, int listenport, int connectport);
abstract public List<String> getCurrentMappings(); abstract public List<String> getCurrentMappings();

View File

@ -9,15 +9,17 @@ public class LinuxIpMapper extends IpMapper {
} }
@Override @Override
public void addMapping(String ip) { public void addMapping(String ip, int listenport, int connectport) {
runCommand("iptables", "-t", "nat", "-A", "OUTPUT", runCommand("iptables", "-t", "nat", "-A", "OUTPUT",
"-p", "all", "-d", ip, "-j", "DNAT", "--to-destination", "127.0.0.1"); "-p", "all", "-d", ip, "--dport", listenport+"", "-j", "DNAT",
"--to-destination", "127.0.0.1:"+connectport);
} }
@Override @Override
public void deleteMapping(String ip) { public void deleteMapping(String ip, int listenport, int connectport) {
runCommand("iptables", "-t", "nat", "-D", "OUTPUT", runCommand("iptables", "-t", "nat", "-D", "OUTPUT",
"-p", "all", "-d", ip, "-j", "DNAT", "--to-destination", "127.0.0.1"); "-p", "all", "-d", ip, "--dport", listenport+"", "-j", "DNAT",
"--to-destination", "127.0.0.1:"+connectport);
} }
@Override @Override

View File

@ -10,12 +10,12 @@ public class MacIpMapper extends IpMapper {
} }
@Override @Override
public void addMapping(String ip) { public void addMapping(String ip, int listenport, int connectport) {
runCommand("ifconfig", "lo0", "alias", ip); runCommand("ifconfig", "lo0", "alias", ip);
} }
@Override @Override
public void deleteMapping(String ip) { public void deleteMapping(String ip, int listenport, int connectport) {
runCommand("ifconfig", "lo0", "-alias", ip); runCommand("ifconfig", "lo0", "-alias", ip);
} }

View File

@ -12,12 +12,12 @@ public class WindowsIpMapper extends IpMapper {
} }
@Override @Override
public void addMapping(String ip) { public void addMapping(String ip, int listenport, int connectport) {
runCommand("netsh", "interface", "ip", "add", "address", "\"Loopback\"", ip, "255.255.255.255"); runCommand("netsh", "interface", "ip", "add", "address", "\"Loopback\"", ip, "255.255.255.255");
} }
@Override @Override
public void deleteMapping(String ip) { public void deleteMapping(String ip, int listenport, int connectport) {
runCommand("netsh", "interface", "ip", "delete", "address", "\"Loopback\"", ip); runCommand("netsh", "interface", "ip", "delete", "address", "\"Loopback\"", ip);
} }