get ip address from url - vb.net

I am trying to get country location from the ip address which I am also looking up from actual url. However for certain urls I am getting the following error:
The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for
I wanted to use the following code to identify the proxy perhaps but since this is a regular console app I am not sure how to get around it. Here is my code;
For Each prod In querylist
If myfetcher.getHtml(prod, userAgent, page) Then
' The lines below I use to find proxy ip
' but error name 'Request' not declared
' Dim nowip As String
' nowip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
' If nowip = "" Then
'nowip = Request.ServerVariables("REMOTE_ADDR")
'End If
'
If prod.Contains("http://") Then
prod = Regex.Replace(prod, "http://", "")
End If
badHost = prod
Dim ipEntry As IPHostEntry = Dns.GetHostByName(prod)
Dim IPAdd As IPAddress() = ipEntry.AddressList
Dim i As Integer = 0
For i = 0 To IPAdd.GetUpperBound(0)
number = number & "IP Address {0}:{1}" & IPAdd(i).ToString
Next
IPList.Add(prod & " " & number)
number = ""
Else
badList.Add(prod)
number = ""
End If
count = count + 1
Next

Here's a language agnostic way to do it:
do a HTTP GET for
domain2ip.net/:url
like
http://domain2ip.net/www.edresearch.co.jp
is
122.200.237.66
you can even to it from JavaScript
$.getJSON("http://domain2ip.net/google.com", callback);
Disclosure: it's my site, and open source.

Related

No matching records found (ODBC -2028) in SAP DI Service Call

When I try to make a new service call I get a No matching records found (ODBC -2028) here is my code:
Dim sC = company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oServiceCalls)
sC.CustomerCode = recordSet.Fields.Item(2).Value Logging(sC.CustomerCode)
sC.Subject = recordSet.Fields.Item(3).Value
sC.Description = recordSet.Fields.Item(5).Value
sC.InternalSerialNum = recordSet.Fields.Item(11).Value
sC.ItemCode = recordSet.Fields.Item(11).Value
Dim ret = sC.Add()
If ret <> 0 Then company.GetLastError(ErrCode, ErrMsg)
Logging("Error in service call: " + ErrCode.ToString() + " : " + ErrMsg)
End If
Every value is valid. When I remove the InternalSerialNum line. it is working. The InetrnalSerialNum is valid too. And on the other machine, this code is working.
How can I solve that problem?

Multiple IP pinging

If My.Computer.Network.Ping("192.168.20.251") Then
Console.WriteLine("IP FOUND")
Else
Console.WriteLine("IP NOT FOUND")
End If
Is there a way to ping an array of IP address and display if how many is online and offline?
Let's consider ListOfIPs is a List(Of String) or a string array that is already populated.
I can't clearly understand if you just want to the number of online IPs and offline.
Here's a solution to do both: show which one is ON/OFF, and count them.
Dim IpIsOn as Integer = 0
Dim IpIsOff as Integer = 0
For Each ip as String in ListOfIPs
If My.Computer.Network.Ping(ip) Then
Console.WriteLine(ip & " is online")
IpIsOn = IpIsOn + 1
Else
Console.WriteLine(ip & " is offline")
IpIsOff = IpIsOff + 1
End If
Next
Console.WriteLine("A total of " & IpIsOn & " IP are online, while " & IpIsOff & " are offline.")
Yes, this can be done by putting the IP addresses that you want into an array and loop through that array and then test every IP.
Code (not tested, but should give you the idea):
Dim list As New List(Of String)
list.Add("192.168.20.251")
list.Add("192.168.233.1")
list.Add("192.168.0.199")
list.Add("192.168.2.55")
For Each item As String In list
If My.Computer.Network.Ping(item) Then Console.WriteLine("IP FOUND " + item) Else Console.WriteLine("IP NOT FOUND " + item) End If
Next

Copying a portion of a string using vba

I have to get username from MeetingItem.Recipient, I tried following to get it:
CStr(MeetingItem.Recipient.Address) and got this responce:
"/o=POST/ou=Zuerich/cn=Recipients/cn=eicherr" I have to do loop through all
recipients and get usernames for example if i do loor with code above Ill get:
"/o=POST/ou=Zuerich/cn=Recipients/cn=eicherr"
"/o=POST/ou=Group (FYHF23PDLT)/cn=Recipients/cn=kisslingie0e"
"/o=POST/ou=Group (FYHF23PDLT)/cn=Recipients/cn=katzensteink"
"/O=POST/OU=Bern/cn=Recipients/cn=junkerb"
"/o=POST/ou=Group (FYHF23PDLT)/cn=Recipients/cn=tanzg6a7"
I need only last part of this strings, how can i do that?
note: kisslingie0e and tanzg6a7 this nicknames contains at the end unnecessary three characters that must also be avoided
Or is there another way to get usernames from MeetingItem.Recipient.Adress.
To get Email I did following:
For Each recip In recips
'Obtain the E-mail Address of a Recipient
Dim pa As Outlook.PropertyAccessor
Const PR_SMTP_ADDRESS As String = _
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set pa = recip.PropertyAccessor
Dim email as String
email = CStr(pa.GetProperty(PR_SMTP_ADDRESS))
Debug.Print email
End For
Use Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress to get the SMTP address.
Be prepared to handle nulls and errors.
To get the NT login name (domain account), read the PR_ACCOUNT MAPI property (DASL name http://schemas.microsoft.com/mapi/proptag/0x3A00001F) using Recipient.AddressEntry.PropertyAccessor.GetProperty.
You can also use Recipient.AddressEntry.GetExchangeUser().Alias
The easiest way to remove the leading text is to reverse the string and loop until you find a "/":
Dim email As String, username As String
Dim i As Integer
email = "/o=POST/ou=Group (FYHF23PDLT)/cn=Recipients/cn=kisslingie0e"
'Reverse string
email = StrReverse(email)
'Loop through string until / is found
For i = 1 To Len(email) Step 1
If Mid(email, i, 1) = "/" Then
Exit For
Else
username = username & Mid(email, i, 1)
End If
Next i
'Reverse username
username = StrReverse(username)
If you need to remove the "cn=", do something like this:
username = Split(username, "=")(1)
If the usernames never contain any numbers, you could remove the trail like this:
For i = 1 To Len(username) Step 1
'Loop until a number occurs
If IsNumeric(Mid(username, i, 1)) Then
'Use string until the number
username = Mid(username, 1, i - 1)
Exit For
End If
Next i
Here's another suggestion that works IF the source is consistent in having "Recipients/cn=" just prior to the desired string, it is followed by optionally stripping the last characters if they are numeric in the third or second to last character.
'find the location of constant, set vEM
vLoc = InStr(email, "Recipients/cn=")
vEM = Mid(email, vLoc + 14, 50)
'Check if third to last or second to last character is numeric
vOffset = 0
If IsNumeric(Mid(vEM, Len(vEM) - 2, 1)) Then
vOffset = 3
ElseIf IsNumeric(Mid(vEM, Len(vEM) - 1, 1)) Then
vOffset = 2
Else
vOffset = 0
End If
vEM = Left(vEM, Len(vEM) - vOffset)

VBA Function to connect to WHOIS server and return availability of a .com.au domain

I'm creating a template for a client who wishes to quickly check the availability of dozens of domains at a time. The template must remain as an excel file.
I've installed and used the SEOToolsForExcel which permitted me to query a server and check whether particular domains are available using the isdomainregistered() function. Unfortunately however, the function will always return 'true' (i.e. domain is taken) for all Australian ('.com.au') domains that are thrown at it. I've tried changing the TLD lookup in the xml config file as suggested in this page : http://seotoolsforexcel.com/how-to-setup-tlds-in-seotools-config-xml/
I tried with the following:
<Tld Name="au" WhoIsServer="whois.aunic.net" WhoIsNotFoundRegex="(no match)|(no data found)|(not found)|(no entries found)|(error for)|(invalid pattern)|(illegal question)" WhoIsCreatedRegex="" WhoIsUpdatedRegex="(?:Last Modified:\s*(\d{2}-[A-z]{3}-)\d{4})" WhoIsExpiresRegex="" WhoIsDelayMs="1000" />
and this one:
<Tld Name="au" WhoIsServer="whois-check.ausregistry.net.au" WhoIsNotFoundRegex="is free" WhoIsCreatedRegex="" WhoIsUpdatedRegex="" WhoIsExpiresRegex="" WhoIsDelayMs="1000" />
But neither seemed to have worked. I've checked with other services that clearly show that the domains are available, yet the SEOTool keeps returning false results (only on '.com.au' domains, '.com' domains work fine).
Thus, my next attempt is to code a custom function in excel to take the domain and send it through to the Ausregistry.com.au server's domain-availability tool.
Ausregistry explains how this can be done in their page here:http://www.ausregistry.com.au/tools/domain-availability
They explain:
The service will then respond with either the string 'Available' or 'Not Available' depending upon the availability of the Domain Name.
For Example
To check the availability of ausregistry.net.au follow these steps:
Connect to: Address: whois-check.ausregistry.net.au, Port: 43
Send the string `ausregistry.net.au\r\n' to the server
The server will respond with `Not Available' and then close the connection.
The above procedure is compatible with standard WHOIS protocol; hence any reseller interface that is built to use WHOIS will be able to use this system as well.
Alternatively, the standard *nix whois command can be used as follows:
whois -h
I've coded plenty in VBA before but I do not know how to implement this connection to the server and how to throw it the domain string and then read the result. I'd appreciate any information on how to achieve this using VBA.
Update. I solved this issue months ago and figured I would post my solution in case anyone stumbles across this. #Lumigraphics, thankfully I didn't have to learn PERL. I used the OstroSoft Winsock Component (you can get it here).
And the following UDF:
Function AusRegDomainAvailable(DomainUrl As String) As Boolean
Dim sPage As String
Dim sServer As String
Dim nPort As Long
Dim AusRegistryServer As String
Dim ReturningData As String
Dim wsTCP As OSWINSCK.Winsock
Dim FixedDomain As String
Dim Timelimit As Date
QueryTimeOut = False
FixedDomain = Replace(DomainUrl, "www.", "")
FixedDomain = Replace(FixedDomain, "http://", "")
FixedDomain = Replace(FixedDomain, "https://", "")
AusRegistryServer = "whois-check.ausregistry.net.au"
nPort = 43
sServer = Trim(AusRegistryServer)
If InStr(sServer, "://") > 0 Then sServer = Mid(sServer, InStr(sServer, "://") + 3)
If InStr(sServer, "/") > 0 Then
sPage = Mid(sServer, InStr(sServer, "/") + 1)
sServer = Left(sServer, InStr(sServer, "/") - 1)
End If
If InStr(sServer, ":") > 0 Then
nPort = Mid(sServer, InStr(sServer, ":") + 1)
sServer = Left(sServer, InStr(sServer, ":") - 1)
End If
If sServer = "" Then Err.Raise 12001, , "Invalid URL"
Set wsTCP = CreateObject("OSWINSCK.Winsock")
wsTCP.Connect sServer, nPort
Do Until wsTCP.State = 7
DoEvents
If wsTCP.State = sckError Then
Exit Function
End If
Loop
wsTCP.SendData FixedDomain & vbCrLf
Timelimit = (Now + TimeValue("0:00:02"))
Do Until wsTCP.Status = "Data Arrival" Or Now > Timelimit
DoEvents
If wsTCP.State = sckClosed Then
QueryTimeOut = True
Exit Function
End If
Loop
wsTCP.GetData ReturningData
ReturningData = Replace(ReturningData, vbLf, "")
ReturningData = Replace(ReturningData, vbCr, "")
ReturningData = Trim(ReturningData)
If ReturningData = "Available" Then
AusRegDomainAvailable = True
ElseIf ReturningData = "Not Available" Then
AusRegDomainAvailable = False
Else
QueryTimeOut = True
AusRegDomainAvailable = Null
End If
DoEvents
Debug.Print FixedDomain & " " & ReturningData
wsTCP.CloseWinsock
Exit Function
ErrHandler:
AusRegDomainAvailable = "Error " & Err.Number & ": " & Err.Description
End Function

Network Discovery Program

I m trying to understand and modifying a network discovery program..if somebody help me understand the following code i'd be obliged
Dim DomainEntry As New DirectoryEntry("WinNT://" & workGroup.Trim())
DomainEntry.Children.SchemaFilter.Add("computer")
X = 5 : Y = 5 : Count = 1
For Each Machine As DirectoryEntry In DomainEntry.Children
Dim CompNode As New TreeNode(), CompInfo(1) As String
CompInfo(0) = Machine.Name
Dim Tempaddr As System.Net.IPHostEntry = Nothing
Try
Tempaddr = DirectCast(Dns.GetHostByName(Machine.Name), System.Net.IPHostEntry)
Dim TempAd As System.Net.IPAddress() = Tempaddr.AddressList, str As String = ""
For Each TempA As IPAddress In TempAd
CompInfo(1) = TempA.ToString()
Next
Catch ex As Exception
CompInfo(1) = ""
End Try
Hopefully this helps:
''//The variable "workGroup" holds your Active Directory domain name
''//The "DomainEntry" variable will represent the root of your Active Directory hierarchy
Dim DomainEntry As New DirectoryEntry("WinNT://" & workGroup.Trim())
''//Tell the "DomainEntry" variable to only look at "computer" objects
DomainEntry.Children.SchemaFilter.Add("computer")
''//These variables are not used
X = 5 : Y = 5 : Count = 1
''//Loop through all of the computers in the domain
For Each Machine As DirectoryEntry In DomainEntry.Children
''//First variable is not used, second is an array with two parts
Dim CompNode As New TreeNode(), CompInfo(1) As String
''//Set the first part of the array to the machine name
CompInfo(0) = Machine.Name
''//The next block tries to get the machine IP by looking it up in DNS. It can fail at several points so it gets wrapped in a try/catch just in case
Dim Tempaddr As System.Net.IPHostEntry = Nothing
Try
''//Try getting the machine IP
Tempaddr = DirectCast(Dns.GetHostByName(Machine.Name), System.Net.IPHostEntry)
''//A machine can have several IP addresses so this gets a full list of them
Dim TempAd As System.Net.IPAddress() = Tempaddr.AddressList, str As String = ""
''//Most machines will probably have just one IP address, but just in case this code takes the last one that it finds
For Each TempA As IPAddress In TempAd
''//Set the second part of our array to the IP address
CompInfo(1) = TempA.ToString()
Next
Catch ex As Exception
''//If this is hit then there was a problem getting the IP address so set it to blank
CompInfo(1) = ""
End Try
Next
This is a program for reading a local Active Directory. "WinNT://workgroup" is the address of the directory.
The next line
DomainEntry.Children.SchemaFilter.Add("computer")
Indicates that you're only interested in items of type "computer". From there on, you're creating a two dimensional array which represents the computers with the machine name in the zeroth element, and the IP address of the machine in the second. If there is more than one IP entry for the machine, the array will contain the last one.