python3.4.3
How can get ip address?
I try this way:
print(socket.gethostbyname(socket.gethostname()))
but only get 127.0.0.1
how can I get the real ip ??
You could try
socket.getfqdn()
or
socket.gethostbyname(socket.getfqdn())
socket.gethostbyname(socket.gethostname()) returns 127.0.0.1 on machines having the hostname in /etc/hosts as 127.0.0.1
Related
Is there a way to find local IPs for devices on your network? I have tried the following in a command line:
Ipconfig
ping 10.51....
arp -a
Is this correct and if not what is?
For Windows
ipconfig
For linux
ifconfig ,
ip addr
in linux you will find ip of eth0 and lo(look up that is for self-connection)
I need some information about routing public IP addresses assigned to the hypervisor into a VM.
I have installed XEN hypervisor on Centos 6.5, I have one NIC with IP 80.86.84.34 & Mask:255.255.255.0 I have an additional IP 85.25.14.195 & Mask: 255.255.255.255
Dom0 has eth0 & virbr0 with a virtual dhcp, the VM has address 192.168.122.4 & Mask:255.255.255.0 the VM has working outbound internet connection.
How do I correctly set dom0 to route connections for 85.25.14.195 into the VM?
Many thanks for your help and apologies if this is a basic question that has been answered before, please point me in the right direction.
First EDIT
I have managed to route the public IP by adding the below route in Dom0, DomU now correctly responds to packets received by Dom0 for the public IP forwarded over virbr0.
route add -net 85.25.14.195 gw 192.168.122.1 netmask 255.255.255.255
My follow up question is what rule is required in IP tables to allow traffic? As currently it is blocked when the firewall is running.
Second EDIT
OK, so I figured out the iptables, I had to remove the REJECT line on virbr0, I also had to add the following rule to make the outbound IP from Dom0 appear correctly:
-A POSTROUTING -s 192.168.122.2 -p tcp -j SNAT --to 85.25.14.195
You should be able to assign 85.25.14.195 as alias IP on virbr0 ( may be virbr0:1 ) and do simple IP Nat or forwarding. You need to do # sysctl -w net.ipv4.ip_forward=1 to be able to forward traffic coming on Public IP to internal Private IP.
I am working with Unix and I used nslookup on a machine at my college.
I got the following output:
Server: ...
Address: ...#**
Name: (name of the machine)
Address: ...
With the *s replaced with the actual numbers.
Which of these numbers is the IP address and which is the MAC address?
xxx.xxx.xxx.xxx is the IP
xx:xx:xx:xx:xx:xx is the MAC address
What network tool can I use under DOS/windows to find the ip address of a netbios host as easily as is done in Linux?
For example under Linux (ubuntu) I can find the ip address like so:
# nmblookup imac
querying imac on 192.168.1.255
192.168.1.75 imac<00>
Now, this is the IP of the macbook when connected wirelessly
But under windows I can't ping it:
C:\>ping imac
Pinging imac.gateway.2wire.net [192.168.1.68] with 32 bytes of data:
Request timed out.
And the closest tool I could find returns TWO IPs
(it returns the hardwired IP even though it got a different IP by connecting wirelessly
C:\>nslookup imac
Address: 192.168.1.254
Name: imac.gateway.2wire.net
Addresses: 192.168.1.68, 192.168.1.75
Isnt there a windows command to return only the active IP address for the host?
On Windows, you can try
ping -a IP_address (lookup for both DNS name and NetBIOS name)
nslookup IP_address (this command requires you to have an internal DNS server configured)
I like to use ping -a personally.
http://technet.microsoft.com/en-us/library/bb490938.aspx :
Nbtstat.exe -a NETBIOSNAME
Nbtstat.exe -A IP
Come with Windows XP and upward.
nbtstat -a [hostname] -c
This gives IP address of NetBIOS name on Windows
I have an IP address and I want to know what is the server name corresponding to that address. How can I do that?
for example: 10.x.x.x to www. something
Use nslookup [IP] [some DNS server]
For internal networks (like 10.x.x.x), something like this:
> nslookup 10.1.1.10 10.1.1.1
Server: 10.1.1.1
Address: 10.1.1.1#53
10.1.1.10.in-addr.arpa name = my-ip-10.1.1.10.domain.com