MCPcopy
hub / github.com/InstaPy/InstaPy / check_browser

Function check_browser

instapy/login_util.py:162–228  ·  view source on GitHub ↗
(browser, logfolder, logger, proxy_address)

Source from the content-addressed store, hash-verified

160
161
162def check_browser(browser, logfolder, logger, proxy_address):
163 # set initial state to offline
164 update_activity(
165 browser,
166 action=None,
167 state="trying to connect",
168 logfolder=logfolder,
169 logger=logger,
170 )
171
172 # check connection status
173 try:
174 logger.info("-- Connection Checklist [1/2] (Internet Connection Status)")
175 browser.get("view-source:https://freegeoip.app/json")
176 pre = browser.find_element(By.TAG_NAME, "pre").text
177 current_ip_info = json.loads(pre)
178 if (
179 proxy_address is not None
180 and socket.gethostbyname(proxy_address) != current_ip_info["ip"]
181 ):
182 logger.warning("- Proxy is set, but it's not working properly")
183 logger.warning(
184 '- Expected Proxy IP is "{}", and the current IP is "{}"'.format(
185 proxy_address, current_ip_info["ip"]
186 )
187 )
188 logger.warning("- Try again or disable the Proxy Address on your setup")
189 logger.warning("- Aborting connection...")
190 return False
191 else:
192 logger.info("- Internet Connection Status: ok")
193 logger.info(
194 '- Current IP is "{}" and it\'s from "{}/{}"'.format(
195 current_ip_info["ip"],
196 current_ip_info["country_name"],
197 current_ip_info["country_code"],
198 )
199 )
200 update_activity(
201 browser,
202 action=None,
203 state="Internet connection is ok",
204 logfolder=logfolder,
205 logger=logger,
206 )
207 except Exception:
208 logger.warning("- Internet Connection Status: error")
209 update_activity(
210 browser,
211 action=None,
212 state="There is an issue with the internet connection",
213 logfolder=logfolder,
214 logger=logger,
215 )
216 return False
217
218 # check if hide-selenium extension is running
219 logger.info("-- Connection Checklist [2/2] (Hide Selenium Extension)")

Callers 1

login_userFunction · 0.85

Calls 2

update_activityFunction · 0.85
execute_scriptMethod · 0.80

Tested by

no test coverage detected