File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Python_Begginer_Projects/Easy Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ import urllib .request
2
+ import urllib .error
3
+
4
+ def URL_CHECK (url ):
5
+ print ('Checking connectivity...' )
6
+
7
+ try :
8
+ response = urllib .request .urlopen (url )
9
+ print ('Connected to ' + url + ' successfully' )
10
+ print (f'Response code: { response .getcode ()} ' )
11
+ except urllib .error .URLError as e :
12
+ print (f'Failed to connect to { url } . Reason: { e .reason } ' )
13
+
14
+ def main ():
15
+ user_url = input ('Enter a URL (include http:// or https://): ' )
16
+
17
+ # Check if the URL starts with http:// or https://
18
+ if not user_url .startswith (('http://' , 'https://' )):
19
+ print ("Invalid URL. Please ensure it starts with 'http://' or 'https://'." )
20
+ return
21
+
22
+ URL_CHECK (user_url )
23
+
24
+ if __name__ == '__main__' :
25
+ main ()
You can’t perform that action at this time.
0 commit comments