Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9044685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:02:53+00:00 2026-06-16T11:02:53+00:00

I have a python script I wrote that connects me to a VPN. Before

  • 0

I have a python script I wrote that connects me to a VPN. Before it does so, it tests my external IP, and records the output as a variable, “originip” then it connects to my vpn, and runs the test again. It displays my originip, then my newip, then it runs a conditional if that tests if origin ip and newip are the same then say there was an error. I’ll add additional logic there later. Currently, the program works fine but it always prints “there was an error, resetting” instead of going to the Else line and printing “you are now connected successfully”

I think there’s something wrong with my if logic here:

if newip and originip == originip:
    print "there was an error, resetting..."
else:
    print "You are now connected successfully"

So I’ve tested the above, and when my VPN connects ok, it reports the new and the old IP address as different, then prints “there was an error, resetting”
If it connects, and displays both newip and originip as the same, it also goes to print “there was an error, resetting…”

I have not been able to get it to execute the else part of that above statement.

Here’s the entire python side of the program

#!/usr/bin/env python
import pexpect
import sys
import os
import time
import subprocess
secdelay = int(raw_input("How many seconds before resetting? "))
p = subprocess.Popen(["./checkmyip.sh"], shell=False, stdout=subprocess.PIPE)
originip = p.stdout.read()
print 'Public IP Address is', originip
child = pexpect.spawn ('./vpn.sh -arg1')
child.expect ('')
child.expect ('(?i)Enter Aut Username:')
child.sendline ('myusername')
child.expect ('(?i)Enter Auth Password:')
child.sendline ('mypassword')
print "Establishing connection..."
time.sleep(10)
p = subprocess.Popen(["./checkmyip.sh"], shell=False, stdout=subprocess.PIPE)
newip = p.stdout.read()
print "The New IP is ",newip
print "the old IP was ", originip
if newip and originip == originip:
    print "there was an error, resetting..."
else:
    print "You are now connected successfully"
print "sleeping for ",secdelay," seconds"
time.sleep(secdelay)
child.sendcontrol('c')
if child.isalive():
    child.sendcontrol('c')
    child.close()
if child.isalive():
    print 'Child did not exit gracefully.'
else:
    print 'Child exited gracefully.'

Finnaly, here is the code I added to my “checkmyip.sh” script. It’s just a simple wget:

#!/usr/bin/env bash
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

So the script works fine, it’s just this error-checking logic that is confusing me. Why my if x and y == x is not working tho, when x and y both enumerate different values in the print line directly above my if statement, I’m confused on.

Any suggestions or help would be extremely appreciated. Thanks for reading!

Thanks for the help everyone! The fixed code was this:

if newip and originip == originip:

was changed to

if newip == originip:
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:02:54+00:00Added an answer on June 16, 2026 at 11:02 am

    Try this instead:

    if newip == originip:
        print "there was an error, resetting..."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python script I wrote that I need to port to php.
I have a simple python script that i wrote for IDA, but i'am can't
I have a Python command line script that connects to a database, generates files
I have a python script and I wrote it such that it will generate
I have a script that I wrote in python for testing out the sorting
I wrote a Python script that I need to have installed on Windows Server
I have a Python script I recently wrote that I call using the command
I have a python script that runs a program, which generates few .exe files
I have a python script that I want always to run in the background.
I have a Python script that makes use of 'Print' for printing to stdout.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.