Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use specific IP Address
Hi guys,

I'm would like your help since I'm new with socket and packet manipulation.

I'm working on Kali Linux, I have my eth0 with 2 IP address and, how can I force my python program to use the IP address which is the secondary instead of

Here my code:

import mechanize

def viewPage(url):
    browser = mechanize.Browser()
    page = browser.open(url)
    source_code = page.read()
    print source_code

Are you trying to change your public IP address via a script? 192.168.X.X is your internal ip address. The address to differentiate multiple devices on your network, etc. Your public ip address is what displays if you go to a site such as https://whatismyipaddress.com/ or if you type in "ip address" in google's search bar.
I would first verify that you do indeed have 2 ip addresses assigned to the same device "eth0", rather than NIC1 assigned to "eth0" and NIC2 to "eth1" (for example) or perhaps a WiFi connection. I believe in Linux, the command is ifconfig . If they are indeed both assigned to to "eth0", why would you do that? It would be helpful for you to post the output of the "ifconfig" command (between the 'output' code tags, of course).
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Jessie"
Python 3.6.3, IDE: PyCharm 2017 Community Edition
Thanks for your answers, let me explain myself.

I'm not trying to change my Public IP, I can't, that's ISP network.

I have not 2 I have like 200 IP's on my NIC, I already create a script to do that: here the link: https://github.com/juliourena/secipmanager

What I'm trying to do is:

Create an script to visit a list of web site (on a .txt file), but generate that traffic from multiples Internals IP's.

So, I have a Firewall and I would like to test it, for general purpose (throughput, bandwidth, sessions, how many client's it can handle, etc).

This code is an example, but at the end this is what I'm looking for, any help?
You have to deal with the system here. Iptables or just set temporary the mask of the address you don't want to use to
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
(Jul-12-2017, 05:14 PM)wavic Wrote: You have to deal with the system here. Iptables or just set temporary the mask of the address you don't want to use to

I'm able to generate a connection, but I would like to know if is possible to retrieve some info from a page, download something or print the page source code.

With this code I'm able to send traffic using other IP:

My IP address is assigned by DHCP, then I use the command:

# ip address add dev eth0

If I run this code I get the response back from the webpage
s =""
def netPacket(dsthost,dstport,srcip,srcport):
    global s
    #create an INET, STREAMing socket
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    except socket.error:
        print 'Failed to create socket'
    print 'Socket Created'

        remote_ip = socket.gethostbyname( dsthost )
    except socket.gaierror:
        #could not resolve
        print 'Hostname could not be resolved. Exiting'
    #connect using this IP
    #Connect to remote server
    s.connect((remote_ip , int(dstport)))
    print 'Socket Connected to ' + dsthost + ' with ip ' + remote_ip + ' and port ' + dstport + ' from ' + srcip + ':' + str(srcport)
    #Send some data to remote server
    message = "GET / HTTP/1.1\r\n\r\n"
    try :
        #Set the whole string
    except socket.error:
        #Send failed
        print 'Send failed'
    print 'Message send successfully'    

def recv_timeout(the_socket,timeout=2):
    #make socket non blocking

    #total data partwise in an array

    #beginning time
    while 1:
        #if you got some data, then break after timeout
        if total_data and time.time()-begin > timeout:

        #if you got no data at all, wait a little longer, twice the timeout
        elif time.time()-begin > timeout*2:

        #recv something
            data = the_socket.recv(8192)
            if data:
                #change the beginning time for measurement
                #sleep for sometime to indicate a gap

    #join all parts to make final string
    return ''.join(total_data)


print recv_timeout(s)

You can get a web page contend. You already did what is needed for this. Sending a http request.
page = socket.recv(bytes_to_receive)
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  how to get an ip address i can use abrew132 1 361 Apr-26-2017, 12:10 AM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)