How to get IP address for test in Robot Framework? - robotframework

I need to get IP Address of current user to use it in test. verify it it is the same in app table.
how to get IP address?
Did not find anything about it

You can use Evaluate keyword and treat is as a python problem. Using solution from this answer your solution can look something like this:
*** Test Cases ***
Example
${ip}= Evaluate [l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) if l][0][0] socket
Log ${ip}

Related

How do I get the *current* Tor exit node IP address over the control port?

How do I get the external IP address of the current Tor exit node (the one which is in use) without using external services/websites (through curl or otherwise) but only through the Tor control port functionality (using bash or python3).
NOTE: I have been looking for an answer to this question and found this one (which lists all exit nodes) and this one (which does not give the IP address of the current exit node but of some other node). Other answers suggest using external services through curl or otherwise which is not what I am looking for.
I am using GNU/Linux.
cid - is circuit id with currently in use or any other circuit id you want.
1 - by cid we retrieve circuit event whith circuit state , we taking finger print of exit node(last element in path property).
2 - checking network status and take address property.
er = controller.get_circuit(cid).path[-1][0]
ip = controller.get_network_status(er).address
or I not try it yet, there is
get_network_statuses - provides all presently available router status entries
hope it helps.
https://stem.torproject.org/api/control.html

proper way to handle missing IPv6 connectivity

I'm currently looking for a way to properly handle missing IPv6 connectivity.
The use case is, that i resolve a DNS record which might contain AAAA records and connect to each of the resolved IPs. Now the system running that code might not have IPv6 connectivity.
So i'm looking for the proper way to handle this and ignore these records, but only if the host can't connect anyway.
My current approach is:
if ip.To4() == nil && err.(*net.OpError).Err.(*os.SyscallError).Err == syscall.EHOSTUNREACH {
log.Info("ignoring unreachable IPv6 address")
continue
}
But i'm not sure, if there is a better way.
A simple solution would be to use a net.Dialer with DualStack set to true and just Dial() using a name and let the library handle the "happy eyeballs" for you.

Is it possible to build an arp request packet in such a way that will cause a router to forward it over subnets?

What I'm trying to do is get all the ip addresses in my network, and I thought, assuming I know the address of all subnets could use arp requests to achieve that if there was a way to forward these requests over different subnets.
For example , assume I had two hosts
192.168.0.2/24 and 192.168.1.2/24
connected via router using IP addresses 192.168.0.1/16 192.168.1.1/16.
I would like to send an arp request from 192.168.0.2/16 to 192.168.1.2/16.
I thought maybe if the arp request was encapsulated in layer 3 header containing 192.168.1.2/24, or 192.168.1.255/24 as the dsetination this will work.
If it is possible and you know a tool that does that I will be happy to know about this tool.
If it isn't, I would like to know what happens to a packet like the one I described above
I would like to know what happens to a packet like the one I described above
If you encapsulate some info into standard IP-packet, then, naturally, it will be routed to the IP-destination host. Yet if the remote host knew nothing about this non-standard packet, then nothing would happen.
If you really want to get something out of this, you need to have up and running some software server on that remote host, which is able to process your requests. That is, you need some Proxy ARP: either existing implementation, or made of your own.
If you don't have such "an agent" in the target subnetwork, then you're out of luck. Go with sequential IP-scanning until be banned by admin.

OpenBSD, connecting to WPA WiFi with website authentication

I frequently travel by buses, most of which have some sort of WiFi onboard. The usual way to connect to them with an automagical connection manager like Wicd is to select the network and then, upon launching the browser some additional authentication takes place and I'm done. But OpenBSD has no such manager, so I came to use and like the standard ifconfig method. In the standard case, where I have e.g. WEP2 encryption and password authentication, the way to go about it is to first run:
ifconfig iwn0 nwid <network_id> wpakey <password>
and after that:
dhclient iwn0
The question is how to connect in the bus case, where there's no password? So far I tried several things like not specifying the password at all or giving an empty password (rejected immediately), but all of them resulted in output like this:
iwn0: no link ............. sleeping
upon running dhclient.
I dug deeper into the man pages (ifconfig(8)) and found out the following way. I first issue:
ifconfig iwn0 nwid <network_id> -wpa
according to the following excerpt form the manpage:
-wpa Disable Wi-Fi Protected Access.
I then issue:
dhclient iwn0
And after loading any website (and going through the authentication) I have the connection established.

How do I make an outgoing socket to a SPECIFIC network interface?

I have a server with two different network interfaces, each with a different IP address. How can I create a socket so it'll go out a specific IP address?
I'd prefer a python example, but the question is language agnostic, so shoot away.
EDIT: Please don't give me "You can't" as an answer. I mean, it is a computer. I can do anything I like to it, for example - I can programatically disable the one interface I don't want on the fly. I'm looking for something prettier.
You can certainly bind a socket to a specific device.
I don't know how to do it in python, but using the berkeley socket api (in C) you need to call setsockopt(), using the option SO_BINDTODEVICE.
You pass in an interface descriptor, which is of type struct ifreq. Ideally you would get the contents of the interface descriptor by using ioctl(), and requesting SIOCGIFINDEX - passing the name of the interface (eg. eth0) as an argument.
edit: Just did a quick search and found this documentation of the socket methods in python. setsockopt() is amongst them.
Just a little note - what I really needed is to bind to a specific IP, and just for the sake of completeness, the solution is to bind the socket after creation. Source in python:
import socket
s = socket.socket()
s.bind(("127.0.0.1", 0))
s.connect(("321.12.131.432", 80))
import socket
s = socket.socket()
s.bind((get_ip_address('eth0'), 0))
from Quora

Resources