Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
Shells Virtual Desktop
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

how to automatically grab openvz vps ip

BellaBella Member
edited July 2014 in Help

Hi.

I am writing an auto install script for a vpn and I was wondering how I would automatically grab my openvz vps IP and put it into a variable so I can use it to set ip tables.

Comments

  • IPv4: ip -4 addr show venet0 | grep inet | awk '{print $2}' | awk -F/ '{print $1}'

    IPv6: ip -6 addr show venet0 | grep inet6 | awk '{print $2}' | awk -F/ '{print $1}'

    Thanked by 2netomx Boxode
  • blackblack Member

    @Bella said:
    Hi.

    I am writing an auto install script for a vpn and I was wondering how I would automatically grab my openvz vps IP and put it into a variable so I can use it to set ip tables.

     curl getipaddr.net -s | head -n 1 
  • @black said:

     curl getipaddr.net -s | head -n 1 

    If he's using IPTables, that might very well be useless in a NAT situation.

    Thanked by 1netomx
  • blackblack Member

    @Rallias said:
    If he's using IPTables, that might very well be useless in a NAT situation.

    True, assuming he's using NAT.

    Thanked by 1netomx
  • amhoabamhoab Member

    Also try hostname -i.

  • BellaBella Member
    edited July 2014

    @Rallias said:
    IPv4: ip -4 addr show venet0 | grep inet | awk '{print $2}' | awk -F/ '{print $1}'

    The output of that shows two IP's

    [root@tx1 ~]# ip -4 addr show venet0 | grep inet | awk '{print $2}' | awk -F/ '{print $1}'
    127.0.0.1
    192.XXX.XXX.XX

    @black said:

     curl getipaddr.net -s | head -n 1 

    [root@tx1 ~]# curl getipaddr.net -s | head -n 1
    192.XXX.XXX.XX

    That works perfectly, thanks!

  • Bella said: The output of that shows two IP's

    Then pipe it into grep -v ' 127' (watch the space)

  • 5n1p5n1p Member

    Some time ago I found the way with python (cant remember where):


    import socket
    print([(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1])

    for ipv6 i changed it like this:


    import socket
    print([(s.connect(('ipv6.google.com', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)]][0][1])

  • agentsmithagentsmith Member
    edited July 2014
    curl
    

    needs a network connection to setup rules so I use this:

    EXTIP=$(/sbin/ifconfig venet0:0 |sed -rn 's/.*inet addr:(.*)  P-t-P.*/\1/p')
    
Sign In or Register to comment.